【springboot报错】nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException

编程入门 行业动态 更新时间:2024-10-28 01:24:12

【springboot<a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错】nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException"/>

【springboot报错】nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException

java springboot开发api时的报错,没复制全,懒得重现

nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class

问题是在于return的这个class里面没有针对responseBody做处理,意思是要告诉responseBody里对应的那些key在somReturnClass这个类里对应的key是啥(虽然名字一样,但代码不会自动帮你对应上)

@GetMapping("/test")public List<someReturnClass> getResult(){return .....;}

解决方法:

  1. 在someReturnClass加上@Getter和@Setter
@Getter
@Setter
@Builder
public class someReturnClass {private String db;private String table;// ...
}

或者:
2. 在someReturnClass的每个变量名上加上@JsonProperty(“xxx”) ,每个都要加,比较麻烦

@Builder
public class someReturnClass {@JsonProperty("db")private String db;@JsonProperty("table")private String table;// ...
}

更多推荐

【springboot报错】nested exception is com.fasterxml.jackson.databind.exc.InvalidDefi

本文发布于:2024-03-07 15:54:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   exception   nested   springboot   fasterxml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!