jackson反序列化报:FAIL_ON_EMPTY_BEANS

Posted chenry777

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jackson反序列化报:FAIL_ON_EMPTY_BEANS相关的知识,希望对你有一定的参考价值。

异常:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: No serializer found for class com.google.common.cache.CacheStats and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

原因:A反序列化成B,A的部分属性B中没有,会报这个错误

解决办法:

@Configuration
public class JacksonConfig {

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    }
}

以上是关于jackson反序列化报:FAIL_ON_EMPTY_BEANS的主要内容,如果未能解决你的问题,请参考以下文章