3

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 ?

1 Answer 1

2

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']])
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I tryed ``` @JacksonXmlElementWrapper(useWrapping = false, localname = "Transform") ``` And it didn't work, but your code works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.