說明: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