我一直在升級到更高版本的傑克遜(即從org.codehaus ...到com.fasterxml ...),突然間我面對很多怪異的錯誤。經過幾個小時的嘗試和調整,我仍然無法讓它工作,所以我問你們是否可以幫助我。jackson-databind「對象不是聲明類的實例」
我有以下方法:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("getTerminalsByIdAndLocation")
List<SearchResultDto> getTerminalsByIdAndLocation(@QueryParam("location") String location, @QueryParam("id") Integer id) throws BusinessException;
和功能的實現只是沒有在資源庫中查找。
的SearchResultDto看起來是這樣的:
@JsonIgnoreProperties(ignoreUnknown = true)
public class SearchResultDto implements Serializable {
private static final long serialVersionUID = 1L;
private TerminalId terminalId;
private Integer location;
private String streetNumber;
private String postalcoldeCity;
private Status status;
// getters and setters with no annotation or so
}
當我現在打電話給我的方法,我收到以下錯誤:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: object is not an instance of declaring class (through reference chain: java.util.ArrayList[0]-><long package>.SearchResultDto["terminalId"])
了很多努力之後我想我只會刪除terminalId,然後它變爲:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: object is not an instance of declaring class (through reference chain: java.util.ArrayList[0]-><long package>AtmSearchResultDto["location"])
我很笨,這裏有什麼不對?
編輯
我的一切使用@JsonIgnore也嘗試除了String streetNumber
但隨後同樣的異常恰好爲streetNumber
我似乎有一些問題與類裝載機左右。我添加了一些調試輸出(或試圖),並得到如下錯誤:' .SearchResultDto不能轉換爲 .SearchResultDto' –