Skip to content

Instantly share code, notes, and snippets.

@Darguelles
Created July 9, 2019 22:15
Show Gist options
  • Save Darguelles/d9f76f29a74e7ed6e8c305098ea3469b to your computer and use it in GitHub Desktop.
Save Darguelles/d9f76f29a74e7ed6e8c305098ea3469b to your computer and use it in GitHub Desktop.
public static SpringDecoder createSpringDecoder() {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
objectMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
objectMapper.registerModule(new JavaTimeModule());
final MappingJackson2HttpMessageConverter jacksonConverter =
new MappingJackson2HttpMessageConverter(objectMapper);
jacksonConverter.setSupportedMediaTypes(
asList(APPLICATION_JSON, APPLICATION_OCTET_STREAM, APPLICATION_JSON_UTF8));
final ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(jacksonConverter);
return new SpringDecoder(objectFactory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment