Example usage for com.fasterxml.jackson.databind ObjectMapper findAndRegisterModules

List of usage examples for com.fasterxml.jackson.databind ObjectMapper findAndRegisterModules

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper findAndRegisterModules.

Prototype

public ObjectMapper findAndRegisterModules() 

Source Link

Document

Convenience method that is functionally equivalent to: mapper.registerModules(mapper.findModules());

As with #findModules() , no caching is done for modules, so care needs to be taken to either create and share a single mapper instance; or to cache introspected set of modules.

Usage

From source file:com.torchmind.stockpile.client.Stockpile.java

/**
 * Creates a client instance for the specified base URL.
 *
 * @param baseUrl a base URL.//from   w  ww.  j av a 2  s  .c  o  m
 * @return a client instance.
 */
@Nonnull
static Stockpile create(@Nonnull String baseUrl) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();

    Retrofit retrofit = (new Retrofit.Builder()).addConverterFactory(JacksonConverterFactory.create(mapper))
            .baseUrl(baseUrl).build();

    return retrofit.create(Stockpile.class);
}

From source file:com.nike.cerberus.server.config.CmsConfig.java

public static ObjectMapper configureObjectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.findAndRegisterModules();
    om.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    om.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    om.enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    om.enable(SerializationFeature.INDENT_OUTPUT);
    return om;// w  w w  .  j  av  a 2s . c o  m
}

From source file:org.ulyssis.ipp.config.Config.java

/**
 * Create a configuration from the given JSON configuration string.
 *//*from   w w w  .j  a  v  a 2  s  . c o  m*/
public static Optional<Config> fromConfigurationString(String configuration) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    try {
        Config result = mapper.readValue(configuration, Config.class);
        return Optional.of(result);
    } catch (IOException e) {
        LOG.error("Error reading configuration", e);
        return Optional.empty();
    }
}

From source file:de.adorsys.multibanking.hbci.job.ScaRequiredJob.java

private static ObjectMapper objectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.findAndRegisterModules();
    return objectMapper;
}

From source file:com.carlomicieli.jtrains.config.WebConfig.java

@Bean
public ObjectMapper jacksonObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.findAndRegisterModules().setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    return objectMapper;
}

From source file:org.obiba.mica.config.JsonConfiguration.java

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.findAndRegisterModules();
    return mapper;
}

From source file:de.msg.message.jms.JmsConfiguration.java

@Bean
public ObjectMapper objectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.findAndRegisterModules();
    return objectMapper;
}

From source file:com.nike.cerberus.module.CerberusModule.java

/**
 * Object mapper for handling configuration objects in the config bucket.
 *
 * @return Object mapper/* w  w  w.  j  a  va2  s . com*/
 */
@Provides
@Singleton
@Named(CONFIG_OBJECT_MAPPER)
public ObjectMapper configObjectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.findAndRegisterModules();
    om.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
    om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    om.enable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    om.enable(SerializationFeature.INDENT_OUTPUT);
    om.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return om;
}

From source file:de.ks.flatadocdb.index.GlobalIndex.java

protected ObjectMapper getMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping();//from  w w  w .ja v a2 s .  c  o  m
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_OBJECT);
    return mapper;
}

From source file:nl.knaw.huygens.alexandria.markup.client.AlexandriaMarkupClient.java

public AlexandriaMarkupClient(final URI alexandriaMarkupURI, SSLContext sslContext) {
    this.alexandriaMarkupURI = alexandriaMarkupURI;
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.findAndRegisterModules();

    final JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
    jacksonProvider.setMapper(objectMapper);

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(50);//from ww w  .j a  v a 2 s .c o m
    cm.setDefaultMaxPerRoute(50);

    ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
    ClientConfig clientConfig = new ClientConfig(jacksonProvider)//
            .connectorProvider(connectorProvider)//
            .property(ApacheClientProperties.CONNECTION_MANAGER, cm)//
            .property(ClientProperties.CONNECT_TIMEOUT, 60000)//
            .property(ClientProperties.READ_TIMEOUT, 60000);

    if (sslContext == null) {
        if ("https".equals(alexandriaMarkupURI.getScheme())) {
            throw new RuntimeException(
                    "SSL connections need an SSLContext, use: new AlexandriaClient(uri, sslContext) instead.");
        }
        client = ClientBuilder.newClient(clientConfig);

    } else {
        client = ClientBuilder.newBuilder()//
                .sslContext(sslContext)//
                .withConfig(clientConfig)//
                .build();
    }
    rootTarget = client.target(alexandriaMarkupURI);
}