I have xml tag with attribute names which are not restricted to some specific values,like that:
<to amount="345.00" service="service" purpose="rent" account="381"/>
With JacksonXML I'd like to deserialize that elements to the Map<String,String>. What kind of annotations I can use for that?
I used the
@JsonAnySetterannotation to deserialize the XML element to aMap<String, String>. Here's an example:In this example, the addAttribute method is annotated with
@JsonAnySetter, which tells JacksonXML to call this method for any XML attribute that doesn't have a corresponding property in theMyElementclass. The method then adds the attribute name and value to the attributes map.To deserialize the XML element to a
MyElementobject, you can use theXmlMapperclass:After deserialization, the attributes map in the MyElement object will contain the attribute names and values from the XML element.