java springboot開發(fā)api時的報錯,沒復(fù)制全,懶得重現(xiàn)
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class
問題是在于return的這個class里面沒有針對responseBody做處理,意思是要告訴responseBody里對應(yīng)的那些key在somReturnClass這個類里對應(yīng)的key是啥(雖然名字一樣,但代碼不會自動幫你對應(yīng)上)
@GetMapping("/test")
public List<someReturnClass> getResult(){
return .....;
}
解決方法:文章來源:http://www.zghlxwxcb.cn/news/detail-503612.html
- 在someReturnClass加上@Getter和@Setter
@Getter
@Setter
@Builder
public class someReturnClass {
private String db;
private String table;
// ...
}
或者:
2. 在someReturnClass的每個變量名上加上@JsonProperty(“xxx”) ,每個都要加,比較麻煩文章來源地址http://www.zghlxwxcb.cn/news/detail-503612.html
@Builder
public class someReturnClass {
@JsonProperty("db")
private String db;
@JsonProperty("table")
private String table;
// ...
}
到了這里,關(guān)于【springboot報錯】nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!