cn.patterncat.cache.config.ObjectMapperConfig Maven / Gradle / Ivy
package cn.patterncat.cache.config;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/**
* Created by cat on 2019-03-12.
*/
@Configuration
public class ObjectMapperConfig {
// @Bean
// public ObjectMapper objectMapper() {
// return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// }
@Bean
public Jackson2ObjectMapperBuilderCustomizer disableFailOptions() {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
jacksonObjectMapperBuilder.featuresToDisable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
jacksonObjectMapperBuilder.featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
};
}
}