use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class SimpleModuleTest method testMixIns.
/*
/**********************************************************
/* Unit tests; other
/**********************************************************
*/
public void testMixIns() throws Exception {
SimpleModule module = new SimpleModule("test", Version.unknownVersion());
module.setMixInAnnotation(MixableBean.class, MixInForOrder.class);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
Map<String, Object> props = this.writeAndMap(mapper, new MixableBean());
assertEquals(3, props.size());
assertEquals(Integer.valueOf(3), props.get("c"));
assertEquals(Integer.valueOf(1), props.get("a"));
assertEquals(Integer.valueOf(2), props.get("b"));
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class SimpleModuleTest method testSimpleEnumDeserializer.
public void testSimpleEnumDeserializer() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleModule mod = new SimpleModule("test", Version.unknownVersion());
mod.addDeserializer(SimpleEnum.class, new SimpleEnumDeserializer());
mapper.registerModule(mod);
SimpleEnum result = mapper.readValue(quote("a"), SimpleEnum.class);
assertSame(SimpleEnum.A, result);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestAbstractTypes method testCollectionDefaulting.
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testCollectionDefaulting() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleModule mod = new SimpleModule("test", Version.unknownVersion());
// let's ensure we get hierarchic mapping
mod.addAbstractTypeMapping(Collection.class, List.class);
mod.addAbstractTypeMapping(List.class, LinkedList.class);
mapper.registerModule(mod);
Collection<?> result = mapper.readValue("[]", Collection.class);
assertEquals(LinkedList.class, result.getClass());
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestAbstractTypes method testMapDefaultingBasic.
public void testMapDefaultingBasic() throws Exception {
ObjectMapper mapper = new ObjectMapper();
SimpleModule mod = new SimpleModule("test", Version.unknownVersion());
// default is HashMap, so:
mod.addAbstractTypeMapping(Map.class, TreeMap.class);
mapper.registerModule(mod);
Map<?, ?> result = mapper.readValue("{}", Map.class);
assertEquals(TreeMap.class, result.getClass());
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-databind by FasterXML.
the class TestTreeWithType method testIssue353.
public void testIssue353() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@class");
SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null, "TEST", "TEST"));
testModule.addDeserializer(SavedCookie.class, new SavedCookieDeserializer());
mapper.registerModule(testModule);
SavedCookie savedCookie = new SavedCookie("key", "v");
String json = mapper.writeValueAsString(savedCookie);
SavedCookie out = mapper.readerFor(SavedCookie.class).readValue(json);
assertEquals("key", out.name);
assertEquals("v", out.value);
}
Aggregations