This is my JSON
{
"field1": "value1",
"field2": "value2",
"field3": "value3",
"field4": "value4",
"field5": "value5"
}
This is XML which I want to convert to:
<root>
<element1>value1</element1>
<element2>value2</element2>
<element3 element4="value4" element5="value5">value3</element3>
</root>
So basically, I want to make element 4 & 5 as attributes to element3. Hope I am making sense so far.
This is what my pojo to parse JSON looks like
public class JSONMessage {
Date timestamp;
@JsonProperty("field1")
@JacksonXmlProperty(localName = "element1")
String element1;
@JsonProperty("field2")
@JacksonXmlProperty(localName = "element2")
String element2;
@JsonProperty("field3")
@JacksonXmlProperty(localName = "element3")
String element3;
@JsonProperty("field4")
@JacksonXmlProperty(localName = "element4")
String element4;
@JsonProperty("field5")
@JacksonXmlProperty(localName = "element5")
String element5;
}
This is what my pojo to parse JSON to XML looks like
@JacksonXmlRootElement(localName = "linkFoundEvent")
public class XMLMessage {
private Date element1;
private String element1;
private String element2;
@JacksonXmlProperty(localName = "element3")
private Element3 element3;
}
And for Element3, I've written this class -
public class Element3{
@JacksonXmlText
private String element3;
@JacksonXmlProperty(localName = "element4", isAttribute = true)
private String element4;
@JacksonXmlProperty(localName = "element5", isAttribute = true)
private String element5;
}
How can I make Element4 and Element5 as attributes to Element4? Please help! Thanks much in advance.