Search in sources :

Example 31 with SimpleModule

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"));
}
Also used : SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 32 with SimpleModule

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);
}
Also used : SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 33 with SimpleModule

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());
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 34 with SimpleModule

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());
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 35 with SimpleModule

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);
}
Also used : SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)112 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)41 Test (org.junit.Test)13 Version (com.fasterxml.jackson.core.Version)8 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)8 Test (org.testng.annotations.Test)8 TestingTypeDeserializer (com.facebook.presto.spi.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.spi.type.TestingTypeManager)7 Type (com.facebook.presto.spi.type.Type)7 Block (com.facebook.presto.spi.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.spi.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.spi.block.TestingBlockJsonSerde)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 IOException (java.io.IOException)5 JsonParser (com.fasterxml.jackson.core.JsonParser)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)3 Module (com.fasterxml.jackson.databind.Module)3 SimpleSerializers (com.fasterxml.jackson.databind.module.SimpleSerializers)3