Search in sources :

Example 76 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project swagger-core by swagger-api.

the class ObjectMapperFactory method createJsonConverter.

protected static ObjectMapper createJsonConverter() {
    ObjectMapper mapper = new ObjectMapper();
    Module deserializerModule = new DeserializationModule();
    mapper.registerModule(deserializerModule);
    mapper.registerModule(new JavaTimeModule());
    Map<Class<?>, Class<?>> sourceMixins = new LinkedHashMap<>();
    sourceMixins.put(ApiResponses.class, ExtensionsMixin.class);
    sourceMixins.put(ApiResponse.class, ExtensionsMixin.class);
    sourceMixins.put(Callback.class, ExtensionsMixin.class);
    sourceMixins.put(Components.class, ComponentsMixin.class);
    sourceMixins.put(Contact.class, ExtensionsMixin.class);
    sourceMixins.put(Encoding.class, ExtensionsMixin.class);
    sourceMixins.put(EncodingProperty.class, ExtensionsMixin.class);
    sourceMixins.put(Example.class, ExampleMixin.class);
    sourceMixins.put(ExternalDocumentation.class, ExtensionsMixin.class);
    sourceMixins.put(Header.class, ExtensionsMixin.class);
    sourceMixins.put(Info.class, ExtensionsMixin.class);
    sourceMixins.put(License.class, ExtensionsMixin.class);
    sourceMixins.put(Link.class, ExtensionsMixin.class);
    sourceMixins.put(LinkParameter.class, ExtensionsMixin.class);
    sourceMixins.put(MediaType.class, MediaTypeMixin.class);
    sourceMixins.put(OAuthFlow.class, ExtensionsMixin.class);
    sourceMixins.put(OAuthFlows.class, ExtensionsMixin.class);
    sourceMixins.put(OpenAPI.class, OpenAPIMixin.class);
    sourceMixins.put(Operation.class, OperationMixin.class);
    sourceMixins.put(Parameter.class, ExtensionsMixin.class);
    sourceMixins.put(PathItem.class, ExtensionsMixin.class);
    sourceMixins.put(Paths.class, ExtensionsMixin.class);
    sourceMixins.put(RequestBody.class, ExtensionsMixin.class);
    sourceMixins.put(Scopes.class, ExtensionsMixin.class);
    sourceMixins.put(SecurityScheme.class, ExtensionsMixin.class);
    sourceMixins.put(Server.class, ExtensionsMixin.class);
    sourceMixins.put(ServerVariable.class, ExtensionsMixin.class);
    sourceMixins.put(ServerVariables.class, ExtensionsMixin.class);
    sourceMixins.put(Tag.class, ExtensionsMixin.class);
    sourceMixins.put(XML.class, ExtensionsMixin.class);
    sourceMixins.put(Schema.class, SchemaConverterMixin.class);
    mapper.setMixIns(sourceMixins);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
    mapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Module(com.fasterxml.jackson.databind.Module) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap)

Example 77 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project nixmash-blog by mintster.

the class WebConfig method configureMessageConverters.

// endregion
// region Messages
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    objectMapper.registerModule(new JavaTimeModule());
    converter.setObjectMapper(objectMapper);
    converters.add(converter);
    super.configureMessageConverters(converters);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 78 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project feign-reactive by kptfh.

the class JettyReactiveFeign method builder.

public static <T> Builder<T> builder() {
    try {
        HttpClient httpClient = new HttpClient();
        httpClient.start();
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        return new Builder<>(httpClient, new JsonFactory(), objectMapper);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HttpClient(org.eclipse.jetty.client.HttpClient) JettyReactiveHttpClient(reactivefeign.jetty.client.JettyReactiveHttpClient) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JsonFactory(com.fasterxml.jackson.core.async_.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 79 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project kork by spinnaker.

the class HttpClientSdkConfiguration method httpClientSdkFactory.

@Bean
public static SdkFactory httpClientSdkFactory(List<OkHttp3ClientFactory> okHttpClientFactories, Environment environment, Provider<Registry> registry) {
    OkHttpClientConfigurationProperties okHttpClientProperties = Binder.get(environment).bind("ok-http-client", Bindable.of(OkHttpClientConfigurationProperties.class)).orElse(new OkHttpClientConfigurationProperties());
    OkHttpMetricsInterceptorProperties okHttpMetricsInterceptorProperties = Binder.get(environment).bind("ok-http-client.interceptor", Bindable.of(OkHttpMetricsInterceptorProperties.class)).orElse(new OkHttpMetricsInterceptorProperties());
    List<OkHttp3ClientFactory> factories = new ArrayList<>(okHttpClientFactories);
    OkHttp3MetricsInterceptor okHttp3MetricsInterceptor = new OkHttp3MetricsInterceptor(registry, okHttpMetricsInterceptorProperties);
    factories.add(new DefaultOkHttp3ClientFactory(okHttp3MetricsInterceptor));
    OkHttp3ClientConfiguration config = new OkHttp3ClientConfiguration(okHttpClientProperties, okHttp3MetricsInterceptor);
    KotlinModule kotlinModule = new KotlinModule.Builder().build();
    // TODO(rz): It'd be nice to make this customizable, but I'm not sure how to do that without
    // bringing Jackson into the Plugin SDK (quite undesirable).
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(kotlinModule);
    objectMapper.disable(READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    objectMapper.disable(FAIL_ON_EMPTY_BEANS);
    objectMapper.setSerializationInclusion(NON_NULL);
    return new HttpClientSdkFactory(new CompositeOkHttpClientFactory(factories), environment, objectMapper, config);
}
Also used : CompositeOkHttpClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.CompositeOkHttpClientFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ArrayList(java.util.ArrayList) HttpClientSdkFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) OkHttp3MetricsInterceptor(com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor) OkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.OkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) KotlinModule(com.fasterxml.jackson.module.kotlin.KotlinModule) OkHttpClientConfigurationProperties(com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Example 80 with JavaTimeModule

use of com.fasterxml.jackson.datatype.jsr310.JavaTimeModule in project data-transfer-project by google.

the class TaskContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerSubtypes(TaskContainerResource.class);
    List<TaskListModel> taskLists = ImmutableList.of(new TaskListModel("id1", "List 1"));
    List<TaskModel> tasks = ImmutableList.of(new TaskModel("id1", "Write Better tests", "Do this soon", null, null), new TaskModel("id2", "Liberate all the data", "do this in stages", null, null));
    ContainerResource data = new TaskContainerResource(taskLists, tasks);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(TaskContainerResource.class);
    TaskContainerResource deserialized = (TaskContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getLists()).hasSize(1);
    Truth.assertThat(deserialized.getTasks()).hasSize(2);
    Truth.assertThat(deserialized).isEqualTo(data);
}
Also used : TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) Test(org.junit.Test)

Aggregations

JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)81 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)65 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)17 Test (org.junit.Test)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 ParameterNamesModule (com.fasterxml.jackson.module.paramnames.ParameterNamesModule)7 Bean (org.springframework.context.annotation.Bean)7 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)6 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)5 Before (org.junit.Before)4 Primary (org.springframework.context.annotation.Primary)4 StdDateFormat (com.fasterxml.jackson.databind.util.StdDateFormat)3 LocalDateSerializer (com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer)3 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 IOException (java.io.IOException)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 Module (com.fasterxml.jackson.databind.Module)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)2