Created
January 6, 2018 10:09
-
-
Save psamsotha/624d0dc1cc8a00c417e57f8fce8d905d to your computer and use it in GitHub Desktop.
Map XmlAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapAdapter extends XmlAdapter<MapAdapter.MapLike, Map<String, String>> { | |
public static class Entry { | |
public String value; | |
public String key; | |
public Entry() {} | |
public Entry(String value, String key) {} | |
} | |
public static class MapLike { | |
public List<MapAdapter.Entry> entry; | |
} | |
@Override | |
public Map<String, String> unmarshal(MapLike v) throws Exception { | |
Map<String, String> map = new HashMap<>(); | |
for (Entry entry: v.entry) { | |
map.put(entry.key, entry.value); | |
} | |
return map; | |
} | |
@Override | |
public MapLike marshal(Map<String, String> v) throws Exception { | |
MapLike mapLike = new MapLike(); | |
mapLike.entry = new ArrayList<>(); | |
for (Map.Entry<String, String> entry: v.entrySet()) { | |
mapLike.entry.add(new Entry(entry.getKey(), entry.getValue())); | |
} | |
return mapLike; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment