Example usage for com.fasterxml.jackson.datatype.guava GuavaModule GuavaModule

List of usage examples for com.fasterxml.jackson.datatype.guava GuavaModule GuavaModule

Introduction

In this page you can find the example usage for com.fasterxml.jackson.datatype.guava GuavaModule GuavaModule.

Prototype

public GuavaModule() 

Source Link

Usage

From source file:com.axemblr.service.cm.ClouderaManagerClient.java

protected ObjectMapper makeJacksonObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationConfig(//w ww.j a  v a  2  s  .  c  o  m
            mapper.getSerializationConfig().without(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS));
    mapper.registerModule(makeJodaTimeModule());
    mapper.registerModule(new GuavaModule());
    return mapper;
}

From source file:no.ssb.jsonstat.v2.deser.DatasetDeserializerTest.java

@Test
public void testDimensionOrder() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new JsonStatModule());

    URL resource = getResource(getClass(), "dimOrder.json");

    JsonParser jsonParser = mapper.getFactory().createParser(resource.openStream());
    jsonParser.nextValue();// w w  w .j ava2 s  . co  m

    DatasetBuildable deserialize = ds.deserialize(jsonParser, mapper.getDeserializationContext());

    assertThat(deserialize.build().getDimension().keySet()).containsExactly("A", "B", "C");

}

From source file:eu.trentorise.opendata.commons.test.jackson.OdtCommonsModuleTest.java

@Test
public void example1() throws JsonProcessingException, IOException {

    ObjectMapper om = new ObjectMapper();
    om.registerModule(new GuavaModule());
    om.registerModule(new OdtCommonsModule());

    String json = om.writeValueAsString(LocalizedString.of(Locale.ITALIAN, "ciao"));
    LocalizedString reconstructedLocalizedString = om.readValue(json, LocalizedString.class);
}

From source file:org.thelq.stackexchange.api.StackClient.java

public StackClient(String seApiKey) {
    Preconditions.checkNotNull(seApiKey);
    this.seApiKey = seApiKey;
    this.jsonMapper = new ObjectMapper();
    jsonMapper.registerModule(new JodaModule());
    jsonMapper.registerModule(new GuavaModule());
    jsonMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    jsonMapper.registerModule(new SimpleModule() {
        @Override//from   w w w .j  a v a2s  .c  o m
        @SuppressWarnings("unchecked")
        public void setupModule(SetupContext context) {
            super.setupModule(context);
            context.addDeserializers(new Deserializers.Base() {
                @Override
                public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
                        BeanDescription beanDesc) throws JsonMappingException {
                    return new UppercaseEnumDeserializer((Class<Enum<?>>) type);
                }
            });
        }
    });
}

From source file:eu.trentorise.opendata.commons.jackson.TodCommonsModule.java

/**
 * Registers in the provided object mapper the jackson tod commons module
 * and also the required guava module.//from  w  w  w  . java 2 s  .c  o  m
 */
public static void registerModulesInto(ObjectMapper om) {
    om.registerModule(new GuavaModule());
    om.registerModule(new TodCommonsModule());
}

From source file:com.ning.metrics.collector.processing.db.TestMockCounterEventProcessor.java

@Test(groups = "slow")
public void testAddCounterEvents() throws Exception {
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new GuavaModule());

    String jsonData = "{\"namespace\": \"network_id:111\"," + "\"buckets\":["
            + "{\"uniqueIdentifier\": \"member:123\"," + "\"createdDate\":\"2013-01-10\"," + "\"counters\":"
            + "{\"pageView\":1,\"trafficDesktop\":0,\"trafficMobile\":0,\"trafficTablet\":1,\"trafficSearchEngine\":0,\"memberJoined\":1,\"memberLeft\":0,\"contribution\":1,\"contentViewed\":0,\"contentLike\":0,\"contentComment\":0}},"
            + "{\"uniqueIdentifier\": \"content:222\"," + "\"createdDate\":\"2013-01-10\","
            + "\"counters\":{\"pageView\":0,\"trafficDesktop\":0,\"trafficMobile\":0,\"trafficTablet\":0,\"trafficSearchEngine\":0,\"memberJoined\":0,\"memberLeft\":0,\"contribution\":0,\"contentViewed\":1,\"contentLike\":5,\"contentComment\":10}}]}";

    Mockito.when(event.getData()).thenReturn(jsonData);

    counterEventSpoolProcessor.processEventFile(null, serializationType, file, null);

    Mockito.verify(counterEventCacheProcessor, Mockito.times(2)).addCounterEventData(Mockito.anyString(),
            Mockito.<CounterEventData>any());
}

From source file:com.monarchapis.client.resource.AbstractResource.java

private static ObjectMapper getObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();

    mapper.registerModule(new JodaModule());
    mapper.registerModule(new GuavaModule());

    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return mapper;
}

From source file:eu.trentorise.opendata.jackan.ckan.CkanClient.java

/**
 * Retrieves the Jackson object mapper. Internally, Object mapper is
 * initialized at first call./* w ww  . jav a2  s  . c om*/
 */
static ObjectMapper getObjectMapper() {
    if (objectMapper == null) {
        objectMapper = new ObjectMapper();
        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) // let's be tolerant
                .configure(MapperFeature.USE_GETTERS_AS_SETTERS, false) // not good for unmodifiable collections, if we will ever use any
                .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

        // When reading dates, Jackson defaults to using GMT for all processing unless specifically told otherwise, see http://wiki.fasterxml.com/JacksonFAQDateHandling
        // When writing dates, Jackson would add a Z for timezone by CKAN doesn't use it, i.e.  "2013-11-11T04:12:11.110868"                            so we removed it here
        objectMapper.setDateFormat(new SimpleDateFormat(CKAN_DATE_PATTERN)); // but this only works for Java Dates...

        // ...so taken solution from here: http://www.lorrin.org/blog/2013/06/28/custom-joda-time-dateformatter-in-jackson/
        objectMapper.registerModule(new JodaModule());
        objectMapper.registerModule(new GuavaModule());

        objectMapper.registerModule(new SimpleModule() {
            {
                addSerializer(DateTime.class, new StdSerializer<DateTime>(DateTime.class) {
                    @Override
                    public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider)
                            throws IOException {
                        jgen.writeString(ckanDateFormatter.print(value));
                    }

                });

                addDeserializer(DateTime.class, CkanDateDeserializer.forType(DateTime.class));
            }
        });

    }
    return objectMapper;
}

From source file:eu.trentorise.opendata.commons.test.jackson.TodCommonsModuleTest.java

@Test
public void example1() throws JsonProcessingException, IOException {

    ObjectMapper om = new ObjectMapper();
    om.registerModule(new GuavaModule());
    om.registerModule(new TodCommonsModule());

    String json = om.writeValueAsString(LocalizedString.of(Locale.ITALIAN, "ciao"));
    LocalizedString reconstructedLocalizedString = om.readValue(json, LocalizedString.class);
}

From source file:com.googlecode.jmxtrans.guice.JmxTransModule.java

@Nonnull
public static Injector createInjector(@Nonnull JmxTransConfiguration configuration) {
    return Guice.createInjector(new JmxTransModule(configuration),
            new ObjectMapperModule().registerModule(new GuavaModule()));
}