解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation
解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation
文章共275字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
报错如下:
从表面上看:似乎是因为没有序列号转换工具converter的原因,但是springboot实际已经自带jackson序列号转换工具(在spring-boot-starter-web/spring-boot-starter-json包下)。
所以明显不是这个原因。那么真正的原因是什么?
实际上,报这个异常跟序列化的原理有关,不论fastjson/jackson在序列化的时候,都是利用反射找到对象类的所有get方法,获取方法名称,然后首字母小写,作为json的每个key值,而get方法的返回值作为value, 最后添加到json中。
所以,解决办法:给实体类添加好getter方法就行了
更多推荐
已为社区贡献4条内容
所有评论(0)