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.wrmsr.kleist.util.Json.java

public static ObjectMapper newObjectMapper() {
    // TODO: io.airlift.json
    ObjectMapper objectMapper = new ObjectMapper();

    // ignore unknown fields (for backwards compatibility)
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    // use ISO dates
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    // skip fields that are null instead of writing an explicit json null value
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    // disable auto detection of json properties... all properties must be explicit
    objectMapper.disable(MapperFeature.AUTO_DETECT_CREATORS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_FIELDS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_SETTERS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_GETTERS);
    objectMapper.disable(MapperFeature.AUTO_DETECT_IS_GETTERS);
    objectMapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS);
    objectMapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
    objectMapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
    objectMapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);

    objectMapper.registerModules(new Jdk8Module(), new JSR310Module(), new GuavaModule());

    return objectMapper;
}

From source file:com.github.shredder121.gh_event_api.model.json.GHEventApiModule.java

@Override
public void setupModule(SetupContext context) {
    super.setupModule(context);
    // https://github.com/spring-projects/spring-boot/issues/4490
    new GuavaModule().setupModule(context);

    new ParanamerModule().setupModule(context);
}

From source file:org.mayocat.shop.marketplace.store.jdbi.AbstractEntityAndTenantMapper.java

@Override
public EntityAndTenant<Product> map(int index, ResultSet result, StatementContext ctx) throws SQLException {
    Product product = extractEntity(index, result, ctx);

    String slug = result.getString("tenant_entity_slug");
    String defaultHost = result.getString("tenant_entity_default_host");
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new GuavaModule());
    Integer configurationVersion = result.getInt("tenant_entity_configuration_version");
    TenantConfiguration configuration;//from   ww  w  . j  a  v  a  2s. c o  m
    if (Strings.isNullOrEmpty(result.getString("tenant_entity_configuration"))) {
        configuration = new TenantConfiguration(configurationVersion,
                Collections.<String, Serializable>emptyMap());
    } else {
        try {
            Map<String, Serializable> data = mapper.readValue(result.getString("tenant_entity_configuration"),
                    new TypeReference<Map<String, Object>>() {
                    });
            configuration = new TenantConfiguration(configurationVersion, data);
        } catch (IOException e) {
            final Logger logger = LoggerFactory.getLogger(TenantMapper.class);
            logger.error("Failed to load configuration for tenant with slug [{}]", e);
            configuration = new TenantConfiguration();
        }
    }

    Tenant tenant = new Tenant((UUID) result.getObject("tenant_entity_id"), slug, configuration);
    tenant.setFeaturedImageId((UUID) result.getObject("tenant_entity_featured_image_id"));
    tenant.setSlug(slug);
    tenant.setDefaultHost(defaultHost);
    tenant.setCreationDate(result.getTimestamp("tenant_entity_creation_date"));
    tenant.setName(result.getString("tenant_entity_name"));
    tenant.setDescription(result.getString("tenant_entity_description"));
    tenant.setContactEmail(result.getString("tenant_entity_contact_email"));

    return new EntityAndTenant<>(product, tenant);
}

From source file:com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe.java

public JsonJacksonMessageSerDe() {
    this.objectMapper = new ObjectMapper();
    this.objectMapper.registerModule(DefaultScalaModule$.MODULE$);
    this.objectMapper.registerModule(new GuavaModule());
    this.objectMapper.registerModule(new JodaModule());
}

From source file:com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe.java

public YamlJacksonMessageSerDe() {
    objectMapper.registerModule(DefaultScalaModule$.MODULE$);
    objectMapper.registerModule(new GuavaModule());
    objectMapper.registerModule(new JodaModule());
}

From source file:no.ssb.jsonstat.v2.DatasetDeserializationTest.java

@BeforeMethod
public void setUp() throws Exception {
    mapper = new ObjectMapper();
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new JsonStatModule());
}

From source file:com.groupon.jackson.ObjectMapperFactory.java

private static ObjectMapper createModifiableObjectMapper(final String name, final ObjectMapper objectMapper) {
    final SimpleModule module = new SimpleModule(name);
    objectMapper.registerModule(module);
    objectMapper.registerModule(new GuavaModule());
    objectMapper.registerModule(new Jdk7Module());
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JodaModule());
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.WRAP_EXCEPTIONS, false);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setDateFormat(new ISO8601DateFormat());
    return objectMapper;
}

From source file:com.oodlemud.appengine.counter.web.test.guice.providers.ObjectMapperProvider.java

public ObjectMapperProvider() {
    defaultObjectMapper = new ObjectMapper();

    defaultObjectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    defaultObjectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    defaultObjectMapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
    defaultObjectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    defaultObjectMapper.setSerializationInclusion(Include.NON_NULL);

    defaultObjectMapper.registerModule(new JodaModule());
    defaultObjectMapper.registerModule(new ObjectifyJacksonModule());
    defaultObjectMapper.registerModule(new GuavaModule());
}

From source file:com.nesscomputing.jackson.NessJacksonModule.java

@Override
public void configure() {
    // Annotated version (@Json) is also bound to json.
    bind(ObjectMapper.class).annotatedWith(JsonMapper.class).toProvider(NessObjectMapperProvider.class)
            .in(Scopes.SINGLETON);//ww w  . ja v a2s  .c om

    // Annotated version (@Smile) is bound to the smile factory.
    bind(ObjectMapper.class).annotatedWith(SmileMapper.class)
            .toProvider(new NessObjectMapperProvider(new SmileFactory())).in(Scopes.SINGLETON);

    // Default (not annotated) instance is bound to json.
    bind(ObjectMapper.class).toProvider(NessObjectMapperProvider.class).in(Scopes.SINGLETON);

    bind(NessJacksonConfig.class).toProvider(ConfigProvider.of(NessJacksonConfig.class)).in(Scopes.SINGLETON);

    NessObjectMapperBinder.bindJacksonModule(binder()).toInstance(new GuavaModule());
    NessObjectMapperBinder.bindJacksonModule(binder()).toInstance(new JodaModule());

    install(new NessCustomSerializerModule());

    // MrBean is pretty safe to globally install, since it only deserializes types that would otherwise fail.
    NessObjectMapperBinder.bindJacksonModule(binder()).to(MrBeanModule.class);

    NessObjectMapperBinder.bindJacksonModule(binder()).to(AfterburnerModule.class);
}

From source file:org.zalando.baigan.TestConfigurationSerialization.java

@Before
public void init() throws JsonMappingException, JsonGenerationException, IOException {
    mapper = new ObjectMapper().registerModule(new GuavaModule());
    conditionsProcessor = new ConditionsProcessor();

}