解决报错: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_第1张图片

 解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation_第2张图片

解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation_第3张图片

 从表面上看:似乎是因为没有序列号转换工具converter的原因,但是springboot实际已经自带jackson序列号转换工具(在spring-boot-starter-web/spring-boot-starter-json包下)。

解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation_第4张图片

 所以明显不是这个原因。那么真正的原因是什么?

实际上,报这个异常跟序列化的原理有关,不论fastjson/jackson在序列化的时候,都是利用反射找到对象类的所有get方法,获取方法名称,然后首字母小写,作为json的每个key值,而get方法的返回值作为value, 最后添加到json中。

所以,解决办法:给实体类添加好getter方法就行了

解决报错:No converter for [xxx] with preset Content-Type ‘null‘和Could not find acceptable representation_第5张图片

 

你可能感兴趣的:(java,spring,boot,序列化)