Search in sources :

Example 1 with SimpleDeserializers

use of com.fasterxml.jackson.databind.module.SimpleDeserializers in project jackson-databind by FasterXML.

the class SimpleModuleTest method testMultipleModules.

public void testMultipleModules() throws Exception {
    MySimpleModule mod1 = new MySimpleModule("test1", Version.unknownVersion());
    SimpleModule mod2 = new SimpleModule("test2", Version.unknownVersion());
    mod1.addSerializer(SimpleEnum.class, new SimpleEnumSerializer());
    mod1.addDeserializer(CustomBean.class, new CustomBeanDeserializer());
    Map<Class<?>, JsonDeserializer<?>> desers = new HashMap<>();
    desers.put(SimpleEnum.class, new SimpleEnumDeserializer());
    mod2.setDeserializers(new SimpleDeserializers(desers));
    mod2.addSerializer(CustomBean.class, new CustomBeanSerializer());
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(mod1);
    mapper.registerModule(mod2);
    assertEquals(quote("b"), mapper.writeValueAsString(SimpleEnum.B));
    SimpleEnum result = mapper.readValue(quote("a"), SimpleEnum.class);
    assertSame(SimpleEnum.A, result);
    // also let's try it with different order of registration, just in case
    mapper = new ObjectMapper();
    mapper.registerModule(mod2);
    mapper.registerModule(mod1);
    assertEquals(quote("b"), mapper.writeValueAsString(SimpleEnum.B));
    result = mapper.readValue(quote("a"), SimpleEnum.class);
    assertSame(SimpleEnum.A, result);
}
Also used : SimpleDeserializers(com.fasterxml.jackson.databind.module.SimpleDeserializers) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

SimpleDeserializers (com.fasterxml.jackson.databind.module.SimpleDeserializers)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1