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 .....; }
解决方法:
- 在someReturnClass加上@Getter和@Setter
@Getter@Setter@Builderpublic class someReturnClass { private String db; private String table; // ...}
或者:
2. 在someReturnClass的每个变量名上加上@JsonProperty(“xxx”) ,每个都要加,比较麻烦
@Builderpublic class someReturnClass { @JsonProperty("db") private String db; @JsonProperty("table") private String table; // ...}
来源地址:https://blog.csdn.net/virusos/article/details/128614270