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();
}
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;
}
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;
}
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()));
}
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" + "} ]");
}
Aggregations