use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-module-afterburner by FasterXML.
the class TestStdDeserializerOverrides method testStringDeserOverideNoAfterburner.
public void testStringDeserOverideNoAfterburner() throws Exception {
final String json = "{\"field\": \"value & value\"}";
final String EXP = "value & value";
Issue59Bean resultVanilla = new ObjectMapper().registerModule(new SimpleModule("module", Version.unknownVersion()).addDeserializer(String.class, new DeAmpDeserializer())).readValue(json, Issue59Bean.class);
assertEquals(EXP, resultVanilla.field);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-module-afterburner by FasterXML.
the class TestStdSerializerOverrides method testStringSerOverideNoAfterburner.
public void testStringSerOverideNoAfterburner() throws Exception {
final FooBean input = new FooBean();
final String EXP = "{\"field\":\"Foo:value\"}";
String json = new ObjectMapper().registerModule(new SimpleModule("module", Version.unknownVersion()).addSerializer(String.class, new MyStringSerializer())).writeValueAsString(input);
assertEquals(EXP, json);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestBeanSerializer method testEmptyBean539.
// [Issue#539]
public void testEmptyBean539() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new SimpleModule("test", Version.unknownVersion()) {
@Override
public void setupModule(SetupContext context) {
super.setupModule(context);
context.addBeanSerializerModifier(new EmptyBeanModifier539());
}
});
String json = mapper.writeValueAsString(new EmptyBean());
assertEquals("42", json);
}
use of com.fasterxml.jackson.databind.module.SimpleModule 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()));
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestCustomSerializers method testWithCustomElements.
public void testWithCustomElements() throws Exception {
// First variant that uses per-property override
StringListWrapper wr = new StringListWrapper("a", null, "b");
assertEquals(aposToQuotes("{'list':['A',null,'B']}"), MAPPER.writeValueAsString(wr));
// and then per-type registration
SimpleModule module = new SimpleModule("test", Version.unknownVersion());
module.addSerializer(String.class, new UCStringSerializer());
ObjectMapper mapper = new ObjectMapper().registerModule(module);
assertEquals(quote("FOOBAR"), mapper.writeValueAsString("foobar"));
assertEquals(aposToQuotes("['FOO',null]"), mapper.writeValueAsString(new String[] { "foo", null }));
List<String> list = Arrays.asList("foo", null);
assertEquals(aposToQuotes("['FOO',null]"), mapper.writeValueAsString(list));
Set<String> set = new LinkedHashSet<String>(Arrays.asList("foo", null));
assertEquals(aposToQuotes("['FOO',null]"), mapper.writeValueAsString(set));
}
Aggregations