'Java - XML POJO

I'm trying to create an XMLElement Pojo that would then be converted to a string that would suffice:

result = "<layerA><layerB><itemA><someProperty>100.00</someProperty>......</layerA>

<layerA>
  <layerB>
    <itemA>
        <someProperty>100.00</someProperty>
    </itemA>
    <itemB>
        <differentProperty>AAA</differentProperty>
    </itemB>
  </layerB>
</layerA>

public class layerA

@XmlElement(required = true)
private LayerB layerB;


public class layerB

@XmlElement(required = true)
private LayerB layerB;

@XmlElement(required = true)
private List<Object> items; ?????????

There can be itemA, itemB, itemC, itemD etc --> in the xml they are classified via name itemA, itemB, and can have different properties.

Wondering if there's a quick way to construct that xml, ultimately it would be a string.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source