Search in sources :

Example 1 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project hadoop by apache.

the class StatePool method read.

private void read(DataInput in) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    // define a module
    SimpleModule module = new SimpleModule("State Serializer", new Version(0, 1, 1, "FINAL", "", ""));
    // add the state deserializer
    module.addDeserializer(StatePair.class, new StateDeserializer());
    // register the module with the object-mapper
    mapper.registerModule(module);
    JsonParser parser = mapper.getFactory().createParser((DataInputStream) in);
    StatePool statePool = mapper.readValue(parser, StatePool.class);
    this.setStates(statePool.getStates());
    parser.close();
}
Also used : Version(com.fasterxml.jackson.core.Version) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project deeplearning4j by deeplearning4j.

the class ObjectMapperProvider method module.

public static SimpleModule module() {
    SimpleModule module = new SimpleModule("nd4j");
    module.addDeserializer(INDArray.class, new NDArrayDeSerializer());
    module.addSerializer(INDArray.class, new NDArraySerializer());
    return module;
}
Also used : NDArrayDeSerializer(org.nd4j.shade.serde.jackson.ndarray.NDArrayDeSerializer) NDArraySerializer(org.nd4j.shade.serde.jackson.ndarray.NDArraySerializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 3 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project eureka by Netflix.

the class EurekaJsonJacksonCodec method createObjectMapper.

private ObjectMapper createObjectMapper(KeyFormatter keyFormatter, boolean compact, boolean wrapped) {
    ObjectMapper newMapper = new ObjectMapper();
    SimpleModule jsonModule = new SimpleModule();
    jsonModule.setSerializerModifier(EurekaJacksonJsonModifiers.createJsonSerializerModifier(keyFormatter, compact));
    newMapper.registerModule(jsonModule);
    newMapper.setSerializationInclusion(Include.NON_NULL);
    newMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, wrapped);
    newMapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, false);
    newMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, wrapped);
    newMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    newMapper.addMixIn(Applications.class, ApplicationsJsonMixIn.class);
    if (compact) {
        addMiniConfig(newMapper);
    } else {
        newMapper.addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class);
    }
    return newMapper;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 4 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project feign by OpenFeign.

the class JacksonCodecTest method customDecoder.

@Test
public void customDecoder() throws Exception {
    JacksonDecoder decoder = new JacksonDecoder(Arrays.<Module>asList(new SimpleModule().addDeserializer(Zone.class, new ZoneDeserializer())));
    List<Zone> zones = new LinkedList<Zone>();
    zones.add(new Zone("DENOMINATOR.IO."));
    zones.add(new Zone("DENOMINATOR.IO.", "ABCD"));
    Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(zonesJson, UTF_8).build();
    assertEquals(zones, decoder.decode(response, new TypeReference<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) LinkedList(java.util.LinkedList) List(java.util.List) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project feign by OpenFeign.

the class JacksonCodecTest method customEncoder.

@Test
public void customEncoder() throws Exception {
    JacksonEncoder encoder = new JacksonEncoder(Arrays.<Module>asList(new SimpleModule().addSerializer(Zone.class, new ZoneSerializer())));
    List<Zone> zones = new LinkedList<Zone>();
    zones.add(new Zone("denominator.io."));
    zones.add(new Zone("denominator.io.", "abcd"));
    RequestTemplate template = new RequestTemplate();
    encoder.encode(zones, new TypeReference<List<Zone>>() {
    }.getType(), template);
    assertThat(template).hasBody(//
    "" + "[ {\n" + "  \"name\" : \"DENOMINATOR.IO.\"\n" + "}, {\n" + "  \"name\" : \"DENOMINATOR.IO.\",\n" + "  \"id\" : \"ABCD\"\n" + "} ]");
}
Also used : RequestTemplate(feign.RequestTemplate) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)108 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)39 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 SimpleSerializers (com.fasterxml.jackson.databind.module.SimpleSerializers)4 IOException (java.io.IOException)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JsonParser (com.fasterxml.jackson.core.JsonParser)3 Module (com.fasterxml.jackson.databind.Module)3 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2