JAXB Annotations - Marshall List <String []>

I have this simple object:

@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class SimilarityInfoResult { private String name; private List<String[]> parameters; public SimilarityInfoResult() { } public SimilarityInfoResult(String name, List<String[]> parameters) { this.name = name; this.parameters = parameters; } ... } 

It is displayed as follows:

  <similarityInfoResult> <name>SubstructureSimilarity</name> <parameters> <item>treshold</item> <item>Double</item> </parameters> <parameters> <item>numberOfResults</item> <item>Integer</item> </parameters> </similarityInfoResult> 

Required Conclusion:

 <similarityInfoResult> <name>SubstructureSimilarity</name> <parameters> <parameter> <name>treshold</name> <type>Double</type> </parameter> <parameter> <name>results</name> <type>Integer</type> </parameter> </parameters> </similarityInfoResult> 

How do I do this with annotations? Is it possible? Maybe I have to create a special parameter object and List<Parameter> ? thank you

+4
source share
1 answer

You need to add the Parameter class to store name and type . And change List<String[]> to List<Parameter> .

This way you can more easily control the parsing of the XML parameter object.

And use:

 @XmlElementWrapper(name="parameters") @XmlElement(name="parameter") private List<Parameter> parameters; 

and

 public class Parameter{ private String name; private String type; ... } 
+5
source

All Articles