I\'ll start directly with my question and later on I give more background information.
Simple: I hava a LinkedHashMap
Reflection is the only way for setting properties of generic unknown object.
You can find everything you will need in the docs.
You can create two classes
@XmlAccessorType(XmlAccessType.FIELD)
public class Document {
@XmlElement
private String title;
@XmlElement
private String id;
@XmlElement
private int version;
}
@XmlAccessorType(XmlAccessType.FIELD)
public class MapJson {
@XmlElement
private LinkedHashMap<String, String> documents;
}
and cobvert Object to JSON usingg
Jackson
new org.codehaus.jackson.map.ObjectMapper().writeValueAsString(instanceofMapJson);
Google JSON
new com.google.gson.Gson().toJson(instanceofMapJson);
PS. Using google json, you can remove xml annotations from your classes