關閉Spring Boot的Jsckson的FAIL_ON_EMPTY_BEANS


說明:Spring Boot中默認使用了Jackson做JSON的解析。

解決方法:

1、通過注入Bean來實現

錯誤:

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)

解決:

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

 

參考:

https://www.jianshu.com/p/1eb0929503e1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM