2017-02-14 36 views
1

我一直在升級到更高版本的傑克遜(即從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

+0

我似乎有一些問題與類裝載機左右。我添加了一些調試輸出(或試圖),並得到如下錯誤:' .SearchResultDto不能轉換爲 .SearchResultDto' –

回答

1

長話短說:我搞砸了我的類路徑中,有兩個類加載器,REST方法的實現從數據庫模塊中從一個不同的類加載器獲取實例的地方調用了一個存儲庫。調整我的maven範圍和導入類型後,它現在正在工作!

相關問題