JsonMappingException: Problem deserializing 'setterless' property '': get method returned null
生活随笔
收集整理的這篇文章主要介紹了
JsonMappingException: Problem deserializing 'setterless' property '': get method returned null
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
更改了一下實體類,往實體中添加一個字段之后,接口調用出錯了,控制臺打印的錯誤信息,而且也挺奇怪的,這里只是顯示了一個warning而不是error
2017-12-27 11:16:34.499 WARN 8640 --- [io-8099-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Problem deserializing 'setterless' property 'foreignJoinFields': get method returned null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Problem deserializing 'setterless' property 'foreignJoinFields': get method returned nullat [Source: java.io.PushbackInputStream@4dba74ee; line: 1, column: 927] (through reference chain: com.hyk.controller.parameter.RequestParameter["fields"]->java.util.ArrayList[0]->com.hyk.jdbc.Field["foreignJoinFields"] 我的實體類Field中有一個foreignJoinFields字段,是一個List,,代碼如下:
public class Field {// 省略其他字段和getter、setter方法private List<Field> foreignJoinFields;public List<Field> getForeignJoinFields() {return foreignJoinFields;}public void setForiegnJoinFields(List<Field> foriegnJoinFields) {this.foreignJoinFields = foriegnJoinFields;} } 看到出現這樣的錯誤我也首先想到是方法的問題,反序列化為模型肯定是和getter/setter方法有關,但是貌似看起來都沒有什么問題,后來仔細挨個對比,發現get中的foreign到了set方法中寫成了foriegn,而且set方法中的參數也寫錯了,導致了前端發送請求反序列化時出現錯誤。更改之后:
public class Field {// 省略其他字段和getter、setter方法private List<Field> foreignJoinFields;public List<Field> getForeignJoinFields() {return foreignJoinFields;}public void setForeignJoinFields(List<Field> foreignJoinFields) {this.foreignJoinFields = foreignJoinFields;} } 所以如果遇到這個問題,檢查一下getter和setter方法吧。
總結
以上是生活随笔為你收集整理的JsonMappingException: Problem deserializing 'setterless' property '': get method returned null的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 后渗透-痕迹清理
- 下一篇: OAuth2授权方式