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

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

Introduction

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

Prototype

public ObjectMapper configure(JsonGenerator.Feature f, boolean state) 

Source Link

Document

Method for changing state of an on/off JsonGenerator feature for JsonFactory instance this object mapper uses.

Usage

From source file:com.dynatrace.cf.servicebroker.catalog.CatalogFactory.java

@Bean
Catalog catalog(@Value("${DYNATRACE_SERVICE_PLANS}") String dynatracePlans) throws Exception {
    System.out.println("DYNATRACE_SERVICE_PLANS set to: " + dynatracePlans);
    String serviceId = UUID.nameUUIDFromBytes("Dynatrace_ServiceId_v12".getBytes()).toString();

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    plans = (Map) objectMapper.readValue(dynatracePlans, objectMapper.getTypeFactory()
            .constructMapLikeType(HashMap.class, String.class, DynatracePlan.class));

    for (DynatracePlan p : plans.values()) {
        p.setPlanId();/*from  w  ww.j a v a2 s.  c  o  m*/
        System.out.println("\t\tDynatracePlan: " + p);
    }

    return new Catalog().service().id(UUID.fromString(serviceId)).name("dynatrace").description(
            "Dynatrace is all-in-one full stack performance monitoring and management powered by artificial intelligence")
            .bindable(Boolean.valueOf(true))
            .tags(new String[] { "dynatrace", "performance", "monitoring", "apm", "analytics" }).metadata()
            .displayName("Dynatrace")
            .imageUrl(
                    URI.create("https://assets.dynatrace.com/global/resources/Signet_Logo_RGB_CP_48x48px.png"))
            .longDescription("Dynatrace is all-in-one full stack performance "
                    + "monitoring and management powered by artificial "
                    + "intelligence that provides you with automated application-health "
                    + "and root-cause analysis information to quickly identify "
                    + "performance bottlenecks in browsers, databases and code.")
            .providerDisplayName("Dynatrace LLC").documentationUrl(URI.create("https://help.dynatrace.com"))
            .supportUrl(URI.create("https://support.ruxit.com")).and().addAllPlans(plans).and();
}

From source file:com.hillert.botanic.MainApp.java

/**
 * Configure the Jackson {@link ObjectMapper}. Use the {@link ISO8601DateFormatWithMilliSeconds}
 * to set a custom {@link DateFormat} ensuring that JSON Data are serialized
 * using the {@code ISO8601} format./* w  ww. j a  v  a2s.  c om*/
 */
@Bean
@Primary
public ObjectMapper objectMapper() {
    ObjectMapper objectMapper = super.objectMapper();
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setDateFormat(new ISO8601DateFormatWithMilliSeconds());
    return objectMapper;
}

From source file:org.springframework.cloud.dataflow.server.config.web.WebConfiguration.java

private void setupObjectMapper(ObjectMapper objectMapper) {
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setDateFormat(new ISO8601DateFormatWithMilliSeconds());
    objectMapper.addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class);
    objectMapper.addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
}

From source file:com.animedetour.api.ApiModule.java

@Provides
@Singleton//from ww  w  . j  a  va2  s.c o m
public RestAdapter restAdapter(Monolog logger, OkHttpClient client) {
    RestAdapter.Builder builder = new RestAdapter.Builder();
    builder.setEndpoint("http://animedetour.com");

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    builder.setConverter(new JacksonConverter(mapper));
    builder.setLog(new RestLogAdapter(logger));
    builder.setLogLevel(RestAdapter.LogLevel.BASIC);

    builder.setClient(new OkClient(client));

    RestAdapter adapter = builder.build();

    return adapter;
}

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

@Test(expected = UnsupportedOperationException.class)
public void testGetInstanceUnmodifiableDeserializationConfig() {
    final ObjectMapper objectMapper = ObjectMapperFactory.getInstance();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
}

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

@Test(expected = UnsupportedOperationException.class)
public void testGetInstanceUnmodifiableSerializationConfig() {
    final ObjectMapper objectMapper = ObjectMapperFactory.getInstance();
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}

From source file:com.tomtom.services.notifications.deployment.DeploymentModule.java

@Override
public void configure(@Nonnull final Binder binder) {
    assert binder != null;
    super.configure(binder);

    // Make sure incorrect JSON doesn't return a HTTP 500, but HTTP 400 code.
    GeneralExceptionMapper.addCustomException(JsonParseException.class, false, Status.BAD_REQUEST);

    // Bind APIs to their implementation.
    binder.bind(HelperResource.class).to(HelperResourceImpl.class).in(Singleton.class);
    binder.bind(PendingNotificationsResource.class).to(PendingNotificationsResourceImpl.class)
            .in(Singleton.class);

    // Bind start-up checking class (example).
    binder.bind(StartupCheck.class).asEagerSingleton();

    final ObjectMapper jsonMapper = Json.getCurrentJsonObjectMapper();
    jsonMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    jsonMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
}

From source file:org.springframework.hateoas.hal.ResourceMappingJackson2HttpMessageConverter.java

/**
 * Construct a new {@code ResourceMappingJackson2HttpMessageConverter} with a
 * customized {@link ObjectMapper} to support HAL resources.
 *///from  w ww . j av  a 2 s.  c  om
public ResourceMappingJackson2HttpMessageConverter() {
    super(Resource.class);
    super.setSupportedMediaTypes(
            Collections.singletonList(new MediaType("application", "hal+json", DEFAULT_CHARSET)));
    ObjectMapper objectMapper = getObjectMapper();
    objectMapper.registerModule(new Jackson2HalModule());
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    super.setObjectMapper(objectMapper);
}

From source file:com.epam.ta.reportportal.core.configs.JacksonConfiguration.java

/**
 * //from w w  w  .ja v  a2  s.co m
 * 
 * @return
 */
@Bean(name = "objectMapper")
public ObjectMapper objectMapper() {
    ObjectMapper om = new ObjectMapper();
    om.setAnnotationIntrospector(new JacksonAnnotationIntrospector());
    om.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
    om.registerModule(new JacksonViewAwareModule(om));
    return om;
}

From source file:com.netflix.conductor.server.JerseyModule.java

@Provides
@Singleton/*from  w ww .  j  a v a2 s.  c  o  m*/
public ObjectMapper objectMapper() {
    final ObjectMapper om = new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
    om.setSerializationInclusion(Include.NON_NULL);
    om.setSerializationInclusion(Include.NON_EMPTY);
    return om;
}