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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations