public class JAXBMapAdaptor<T>
extends XmlAdapter<JAXBMapElements<T>,Map<String,T>>
User: Cyokin Zhang
Date: 10/4/13
Time: 11:23 PM
How to use
1. add XmlJavaTypeAdapter on your hashmap property, key must string type
add @XmlSeeAlso(AppSettingInfo.class) on your class, otherwise it will throw exception that JAXB can;t find your context
[@]XmlRootElement(name="Application")
[@]XmlSeeAlso(AppSettingInfo.class)
public class ConfigurationInfo {
[@]XmlJavaTypeAdapter(value=JAXBMapAdaptor.class)
[@]XmlElement(name="AppSettings")
public HashMap AppSettings;
}
2. Specific which one is hash key in your object
[@]XmlRootElement(name="Add")
public class AppSettingInfo {
[@]XmlAttribute(name="key")
[@]JAXBMapKeyAttribute
public String Key;
[@]XmlAttribute(name="value")
public String Value;
}