Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is My Configuration file for Jackson JSON(Faster XML) in Spring BOOT
- @Bean
- public MappingJackson2HttpMessageConverter jackson2Converter() {
- MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
- converter.setObjectMapper(objectMapper());
- return converter;
- }
- @Bean
- public ObjectMapper objectMapper() {
- Object objectMapper = new ObjectMapper();
- // ((ObjectMapper) objectMapper).registerModule(new Hibernate4Module());
- ((ObjectMapper) objectMapper)
- .enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
- // to allow serialization of "empty" POJOs (no properties to serialize)
- // (without this setting, an exception is thrown in those cases)
- ((ObjectMapper) objectMapper)
- .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- // to write java.util.Date, Calendar as number (timestamp):
- ((ObjectMapper) objectMapper)
- .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- // DeserializationFeature for changing how JSON is read as POJOs:
- // to prevent exception when encountering unknown property:
- ((ObjectMapper) objectMapper)
- .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- // to allow coercion of JSON empty String ("") to null Object value:
- ((ObjectMapper) objectMapper)
- .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
- return (ObjectMapper) objectMapper;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement