I found cool Jackson XML library:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.10</version>
<type>bundle</type>
</dependency>
It works with no extra configurations:
val xmlMapper = XmlMapper()
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
xmlMapper.writeValueAsString(CustomIntegration)
where CustomIntegration
is a data class
data class CustomIntegration(val name: String)
For an input CustomeIntegration("Integration A")
, an output will be
<CustomIntegration>
<name>
Integrartion A
</name>
</CustomIntegration>
The question is how I can change CustomIntegration
to integration
when deserializing to XML? There are numbers of use-cases I want to address:
- Single implementation for any class, so
CoolIntegration
,AwesomeIntegration
all will convert into tagintegration
- I cannot just rename class
CustomIntegration
intointegration
because it is almost likeSOAP:envelope
into SOAP integrations, so in the same tag can be with different content - Ideally, I want to write as little code as possible, to simplify the maintenance of it
The only solution I found so far is to write custom deserializers but this wouldn't fully address all non-functional requirements I am trying to meet.