I have problem with serialization. I have XML :
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped"/>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC"/>
</ds:Transforms>
Tag Transform is empty but has attribute.
Pojo Transforms:
@Data
public class Transforms {
@JacksonXmlProperty(localName = "Transform")
@JacksonXmlElementWrapper
private List<Transform> transform;
}
Pojo Transform:
@Data
public class Transform {
@JacksonXmlProperty(isAttribute = true, localName = "Algorithm")
private String algorithm;
}
When I serialize the given XML, the incoming result is:
Transforms(transform=[])
How could I get the list of two Transform with field algorithm ?
Just disable useWrapping
attribute in the @JacksonXmlElementWrapper
by putting false
in Transforms
class. It will work.
Updated code:
@Data
public class Transforms {
@JacksonXmlProperty(localName = "Transform")
@JacksonXmlElementWrapper(useWrapping = false)
private List<Transform> transform;
}
Output on my local:
Transforms(transform=[Transform[algorithm='http://www.w3.org/2000/09/xmldsig#enveloped'], Transform[algorithm='http://www.w3.org/TR/2001/REC']])