# Storing avro fields in XML in database

**URL:** https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925
**Category:** Self-Managed Connectors
**Created:** [1 June 2021 04:30 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925 "2021-06-01T04:30:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![imk](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@imk](https://forum.confluent.io/u/imk)
#### Post date: [1 June 2021 04:30 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/1 "2021-06-01T04:30:51Z")

</div>

Hi,

This is regarding reading data on Kafka Communication Layer in Avro format, where there are different fields.  
However, this data gets stored in database table through JDBC sink connector in same way i.e. in diferent fields.  
Could you please let me know if there is a way to store these different fileds in single XML in database through JDBC sink connector.

---

<div class="post-metadata">

### Author: ![rick](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/rick/32/49_2.png) [@rick](https://forum.confluent.io/u/rick)
#### Post date: [1 June 2021 15:56 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/2 "2021-06-01T15:56:23Z")

</div>

@imk I’m not aware of an XML converter. The use case may require writing a custom converter. Here is documentation on converters: [Kafka Connect Concepts | Confluent Documentation](https://docs.confluent.io/platform/current/connect/concepts.html#converters) Here is a nice post about creating custom converters: [Custom Converters :: Debezium Documentation](https://debezium.io/documentation/reference/development/converters.html)

---

<div class="post-metadata">

### Author: ![whatsupbros](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/whatsupbros/32/239_2.png) [@whatsupbros](https://forum.confluent.io/u/whatsupbros)
#### Post date: [2 June 2021 06:53 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/3 "2021-06-02T06:53:55Z")

</div>

Hi, @imk!

There is this very simple SMT, which can convert the whole Kafka record payload to a single JSON or XML: [GitHub - an0r0c/kafka-connect-transform-tojsonstring: transform-to-json-string is a Single Message Transformation (SMT) for Apache Kafka® Connect to convert a given Connect Record to a single JSON String. It's an UNOFFICIAL community project.](https://github.com/an0r0c/kafka-connect-transform-tojsonstring)

To have the payload in XML, you will only need to add something like this in your JDBC Sink Connector configuration:

```auto
...
"transforms": "ValueToJson",
"transforms.ValueToJson.type": "com.github.cedelsb.kafka.connect.smt.Record2JsonStringConverter$Value",
"transforms.ValueToJson.post.processing.to.xml": "true",
"transforms.ValueToJson.json.string.field.name": "XML_PAYLOAD",
...

```

Hope this helps.

---

<div class="post-metadata">

### Author: ![imk](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@imk](https://forum.confluent.io/u/imk)
#### Post date: [3 June 2021 04:48 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/4 "2021-06-03T04:48:24Z")

</div>

Thanks for the response.  
Smt part is giving an error as invalid value for configuration transforms.ValueToJson.type.  
Invalid value null for configuration.

---

<div class="post-metadata">

### Author: ![whatsupbros](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/whatsupbros/32/239_2.png) [@whatsupbros](https://forum.confluent.io/u/whatsupbros)
#### Post date: [3 June 2021 07:23 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/5 "2021-06-03T07:23:49Z")

</div>

Did you install the SMT itself in your cluster?

---

<div class="post-metadata">

### Author: ![imk](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@imk](https://forum.confluent.io/u/imk)
#### Post date: [3 June 2021 10:21 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/6 "2021-06-03T10:21:40Z")

</div>

Yes, it is there on Kafka Communication layer, where messages are getting stored in Avro format.

---

<div class="post-metadata">

### Author: ![whatsupbros](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/whatsupbros/32/239_2.png) [@whatsupbros](https://forum.confluent.io/u/whatsupbros)
#### Post date: [3 June 2021 10:40 UTC](https://forum.confluent.io/t/storing-avro-fields-in-xml-in-database/1925/7 "2021-06-03T10:40:44Z")

</div>

Can you share your connector configuration and exact error message, which you see in the logs at least?
