Created
August 1, 2012 20:00
-
-
Save lucascs/3230186 to your computer and use it in GitHub Desktop.
converter for maps
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
@Component | |
public class MapConverter implements Converter { //from XStream | |
//unmarshal => empty | |
public boolean canConvert(Class type) { return Map.class.isAssignableFrom(type); } | |
public void marshal(Object value, HierarchicalStreamWriter writer, MarshalingContext context) { | |
Map<String, Object> map = (Map<String, Object>) value; //assuming this | |
for(Entry<String,Object> entry: map.entrySet()) { | |
writer.startNode(entry.getKey()); | |
context.convertAnother(entry.getValue()); | |
writer.endNode(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment