Example usage for com.fasterxml.jackson.databind.module SimpleModule addDeserializer

List of usage examples for com.fasterxml.jackson.databind.module SimpleModule addDeserializer

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.module SimpleModule addDeserializer.

Prototype

public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser) 

Source Link

Usage

From source file:com.aerospike.session.impl.ConfigReader.java

/**
 * Read configuration from the filename provided by the user.
 *///from  w  w  w. j a va2  s  .c  o  m
public AerospikeSessionStoreConfig getConfiguration(String configresourcename) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();

    log.debug("Reading store config from {}.", configresourcename);
    @Cleanup
    final InputStream stream = getClass().getClassLoader().getResourceAsStream(configresourcename);
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Host.class, new HostDeserializer());
    mapper.registerModule(module);
    return mapper.readValue(stream, AerospikeSessionStoreConfig.class);

}

From source file:com.aerospike.cache.ConfigReader.java

/**
 * Read configuration from given file/*from  w w w  .j a  v a  2  s.  c  o m*/
 *
 * @param configresourcename
 * @return
 * @throws IOException
 */
public AerospikeCacheConfig getConfiguration(String configresourcename) throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    log.debug("Reading cache config frm {}.", configresourcename);
    @Cleanup
    final InputStream istream = getClass().getClassLoader().getResourceAsStream(configresourcename);
    SimpleModule module = new SimpleModule();
    module.addDeserializer(Host.class, new HostDeserializer());
    mapper.registerModule(module);
    return mapper.readValue(istream, AerospikeCacheConfig.class);
}

From source file:com.arpnetworking.jackson.EnumerationDeserializerTest.java

@SuppressWarnings("unchecked")
@Test/*from   w  ww .j  a  va  2s .c o m*/
public void testDeserializer() throws Exception {
    final EnumerationDeserializerStrategy<TestEnum> strategy = Mockito
            .mock(EnumerationDeserializerStrategy.class);
    Mockito.doReturn(TestEnum.FOO).when(strategy).toEnum(Mockito.any(Class.class), Mockito.eq("bar"));

    final SimpleModule module = new SimpleModule();
    module.addDeserializer(TestEnum.class, EnumerationDeserializer.newInstance(TestEnum.class, strategy));
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(module);

    final TestClass c = objectMapper.readValue("{\"enum\":\"bar\"}", TestClass.class);
    Mockito.verify(strategy).toEnum(Mockito.any(Class.class), Mockito.eq("bar"));
    Assert.assertEquals(TestEnum.FOO, c.getEnum());
}

From source file:org.jmingo.mapping.marshall.jackson.MongoMapper.java

public MongoMapper() {
    addMixInAnnotations();/* w w w.j av  a 2s. c  o  m*/
    setVisibilityChecker(getSerializationConfig().getDefaultVisibilityChecker()
            .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
            .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
            .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    SimpleModule mongoModule = new SimpleModule();
    mongoModule.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
    mongoModule.addSerializer(ObjectId.class, new ObjectIdSerializer());
    mongoModule.addDeserializer(Date.class, new MongoDateDeserializer());
    mongoModule.addSerializer(Date.class, new BsonDateSerializer());
    registerModule(mongoModule);
}

From source file:org.openmhealth.shim.fitbit.FitbitShimTest.java

@Test
@SuppressWarnings("unchecked")
public void testNormalize() throws IOException {
    URL url = Thread.currentThread().getContextClassLoader().getResource("fitbit-heart.json");
    assert url != null;
    InputStream inputStream = url.openStream();

    ObjectMapper objectMapper = new ObjectMapper();

    FitbitShim.FitbitDataType.HEART.getNormalizer();
    SimpleModule module = new SimpleModule();
    module.addDeserializer(ShimDataResponse.class, FitbitShim.FitbitDataType.HEART.getNormalizer());

    objectMapper.registerModule(module);

    ShimDataResponse response = objectMapper.readValue(inputStream, ShimDataResponse.class);

    assertNotNull(response);/*from  www  . java 2  s.c  om*/

    assertNotNull(response.getShim());

    Map<String, Object> map = (Map<String, Object>) response.getBody();
    assertTrue(map.containsKey(HeartRate.SCHEMA_HEART_RATE));

    List<HeartRate> stepCounts = (List<HeartRate>) map.get(HeartRate.SCHEMA_HEART_RATE);
    assertTrue(stepCounts != null && stepCounts.size() == 6);
}

From source file:org.apache.streams.jackson.MemoryUsageDeserializerTest.java

/**
 * setup./*from ww w  .j  a  va2  s . com*/
 */
@Before
public void setup() {
    objectMapper = StreamsJacksonMapper.getInstance();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(MemoryUsageBroadcast.class, new MemoryUsageDeserializer());
    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

From source file:com.google.gplus.GooglePlusPersonSerDeTest.java

@Before
public void setup() {
    objectMapper = StreamsJacksonMapper.getInstance();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Person.class, new GPlusPersonDeserializer());
    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    googlePlusActivityUtil = new GooglePlusActivityUtil();
}

From source file:pl.edu.pwr.iiar.zak.thermalKit.deserializers.HeaterUnitDeserializerTest.java

@Test
public void testDeserialize() throws Exception {
    RcFileParser parser = new RcFileParser();
    DB db = new MongoClient().getDB(parser.getDatabaseName());

    SimpleModule module = new SimpleModule();
    module.addDeserializer(HeaterUnit.class, new HeaterUnitDeserializer());
    Jongo jongo = new Jongo(db, new JacksonMapper.Builder().registerModule(module).build());

    MongoCollection heatersDBCollection = jongo.getCollection(parser.getHeaterCollection("virtex5"));
    HeaterUnit heaterUnit = heatersDBCollection.findOne(String.format("{ 'type': '%s'}", "RO1"))
            .as(HeaterUnit.class);
}

From source file:org.apache.streams.gplus.GooglePlusPersonSerDeIT.java

/**
 * setup.//from  w  w w .j a  va  2s.  c o m
 */
@BeforeClass
public void setup() {
    objectMapper = StreamsJacksonMapper.getInstance();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Person.class, new GPlusPersonDeserializer());
    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

From source file:com.youtube.processor.YoutubeTypeConverterTest.java

@Before
public void setup() {
    objectMapper = StreamsJacksonMapper.getInstance();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addDeserializer(Video.class, new YoutubeVideoDeserializer());
    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    youtubeTypeConverter = new YoutubeTypeConverter();
    youtubeTypeConverter.prepare(null);//www  . ja  va 2s.c o  m
}