Community
Participate
Working Groups
To work with Map adapter was created. It works fine with JAXB RI, but fails with MOXy: Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field MapEntry.key to [LMapEntry; @XmlRootElement public class Foo { @XmlJavaTypeAdapter(MapAdapter.class) public Map<String, Object> map; } public class MapAdapter extends XmlAdapter<MapEntry[], Map<String, Object>> { @Override public Map<String, Object> unmarshal(MapEntry[] v) throws Exception { Map<String, Object> map = new HashMap<>(); for (MapEntry me : v) map.put(me.key, me.value); return map; } @Override public MapEntry[] marshal(Map<String, Object> v) throws Exception { MapEntry[] mes = new MapEntry[v.size()]; int i = 0; for (Map.Entry<String, Object> entry : v.entrySet()) mes[i++] = new MapEntry(entry.getKey(), entry.getValue()); return mes; } } public class MapEntry { public String key; public Object value; public MapEntry() {} public MapEntry(String key, Object value) { this.key = key; this.value = value; } }
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink