Serialize pojo to xml

Viewed 20

I need to serialise a java pojo to the following xml.

<listdata>
  <listrow>
    <field realfieldname="CustomerIDtext">john.smith</field>
    <field realfieldname="Field1">Mr</field>
    <field realfieldname="Field2">john</field>
    <field realfieldname="Field4">smith</field>
    <field realfieldname="Field5">12345678</field>
  </listrow>
</listdata>

I have tried a few ways but the best I could do is the following:

<listdata>
  <listrow>
    <field>Mr</field>
    <field>John</field>
    <field>Smith</field>
  </listrow>
</listdata>

This is my pojo:

@JacksonXmlRootElement(localName = "listrow")
@Builder
public class ListRow {

  @JacksonXmlElementWrapper(localName = "listrow")
  @JacksonXmlProperty(localName = "field")
  private List<String> field;
  
}

I would appreciate any pointers.

Thanks

0 Answers
Related