Using JAXB, how to map <entry key="childResources"> below?
I tried mapping it to a Map, to a list of @XmlRootElement anotated classes and other ways, without success.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<map>
<entry key="extraProperties">
<map>
<entry key="methods">
<list>
<map>
<entry key="name" value="GET" />
</map>
<map />
<map>
<entry key="name" value="POST" />
<entry key="messageParameters">
<map>
<entry key="id">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="false" />
<entry key="defaultValue" value="" />
<entry key="type" value="string" />
</map>
</entry>
<entry key="enabled">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="true" />
<entry key="defaultValue" value="true" />
<entry key="type" value="boolean" />
</map>
</entry>
<entry key="factoryclass">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="false" />
<entry key="defaultValue" value="" />
<entry key="type" value="string" />
</map>
</entry>
<entry key="description">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="true" />
<entry key="defaultValue" value="" />
<entry key="type" value="string" />
</map>
</entry>
<entry key="target">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="true" />
<entry key="defaultValue" value="server" />
<entry key="type" value="string" />
</map>
</entry>
<entry key="property">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="true" />
<entry key="defaultValue" value="" />
<entry key="type" value="string" />
</map>
</entry>
<entry key="restype">
<map>
<entry key="acceptableValues" value="" />
<entry key="optional" value="false" />
<entry key="defaultValue" value="" />
<entry key="type" value="string" />
</map>
</entry>
</map>
</entry>
</map>
</list>
</entry>
<entry key="commands">
<list />
</entry>
<entry key="childResources">
<map>
<entry key="ab/cd" value="http://localhost:4848/management/domain/resources/custom-resource/ab%2Fcd" />
<entry key="xx" value="http://localhost:4848/management/domain/resources/xx" />
</map>
</entry>
</map>
</entry>
<entry key="message" value="" />
<entry key="exit_code" value="SUCCESS" />
<entry key="command" value="custom-resource" />
</map>
The java.util.Map interface has no provider to marshal/unmarshal its instances. You’ll have to write a class that extends
XmlAdapterand annotate thejava.util.Mapattribute with@XmlJavaTypeAdapter(MyMapAdapter.class).After a while on Google looking for
jax-rs java.util.map, I ended up with the codes bellow. In my case I have named my adapter as XmlStringMapAdapter instead of MyMapAdapter.ServiceDefinition.java
EntryElement.java
MapElement.java
XmlStringMapAdapter.java
And bellow is a class that I used to test the new map adapter.
ServiceResouce.java
Output from the resource above is as shown bellow.