use of com.fasterxml.jackson.databind.ser.std.StdDelegatingSerializer in project jackson-databind by FasterXML.
the class TestCustomSerializers method testDelegating.
// [databind#87]: delegating serializer
public void testDelegating() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule("test", Version.unknownVersion());
module.addSerializer(new StdDelegatingSerializer(Immutable.class, new StdConverter<Immutable, Map<String, Integer>>() {
@Override
public Map<String, Integer> convert(Immutable value) {
HashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
map.put("x", value.x());
map.put("y", value.y());
return map;
}
}));
mapper.registerModule(module);
assertEquals("{\"x\":3,\"y\":7}", mapper.writeValueAsString(new Immutable()));
}
Aggregations