I am looking JAXB annotation class which can be serialized the following json format.
JSON Format : {"name":"xyz","attr1":"attr1value","attr2":"attr2value",.....}}
In above JSON format, name is a mandatory attribute,
others are not but user should be able to pass as much as attributes.
The below JaxB annotation class which can be serialized the JSON format
{"name":"xyz","openContentMap":{"attr1":"attr1value","attr2":"attr2value", so on}}.
But we want to JaxB annotation which can be serialized this format {"name":"xyz","attr1":"attr1value","attr2":"attr2value",.....}}
@XmlRootElement
public class MyJaxbBean {
private String name;
private Map<String, String> openContentMap = new HashMap<String, String>();
@XmlAnyElement
public Map<String, String> getOpenContentMap() {
return openContentMap;
}
@XmlAnyElement
public void setOpenContentMap(String key, String value) {
openContentMap.put(key, value);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MyJaxbBean() {
}
}
Use
org.codehaus.jackson.annotate.JsonAnyGetterandorg.codehaus.jackson.annotate.JsonAnySetterworks well