I have this Object, as a node of a complex Object:
public class Parameter implements Serializable {
@XmlElement(name = "Key")
protected String key;
@XmlElement(name = "Value")
protected Object value;
}
The propety "Value" can either be a String, effectively making the Parameter a Map<String, String>, or it can be another Parameter Value. I have a List of these Objects.
for Example, both below XML snippets are valid:
<Parameter>
<Key>MyKey</Key>
<Value>MyValue</MyValue>
</Parameter>
<Parameter>
<Key>Key1</Key>
<Value>
<Key>Key2</Key>
<Value>
<Key>Key3</Key>
<Value>ValueInString1</Value>
</Value>
<Value>
<Key>Key4</Key>
<Value>ValueInString2</Value>
</Value>
</Value>
What I am looking for is a way of implementing an XMLAdapter that can handle this. The 2 main ideas are:
- Use the Adapter for the whole parameter Class.
- Use the Adapter only for the "Value" Property.
Idea #1 stucks on how to marshal a list of key value pairs Idea #2 stucks on, if the value is a Parameter, how to invoke the Generic Marshaller for Parameter.class
You can use a MapAdapter that converts the Map to an array of MapElements as follows: