2017-02-20 79 views
1

我有一個來自不具有默認構造函數的第三方API的java類之一的反序列化問題。爲了解決這個問題,我使用了JacksonMixIn,它工作正常罰款。但問題是,我有一個REST端點實現在澤西API接受上面提到的類之一作爲從客戶端到服務器端的方法參數。所以當反序列化它會引發下面的錯誤。如何在Jersey REST服務方法參數上使用jackson mixin

No suitable constructor found for type [simple type, class net.rcarz.jiraclient.Priority]: can not instantiate from JSON object (need to add/enable type information?) 
at [Source: [email protected]; line: 1, column: 454]... 

受影響的類

public class TestCaseVO{ 
    private Priority priority; 
    private User reporter; 
} 

public class Priority { 
    protected Priority(RestClient restclient, JSONObject json) { 
    super(restclient); 

    if (json != null) 
     deserialise(json); 
} 
} 

這是用於客戶端通信到服務器

public class myDataObject{ 
     private String userName; 
     private List<TestCaseVO> testCases; 
     //Getter and setters 
    } 

澤西端點

對象
@POST 
    @Path("/bug") 
    @Consumes(MediaType.APPLICATION_JSON) 
    @Produces(MediaType.APPLICATION_JSON) 
    public TestCaseVO attachBugForTestCase(myDataObject myDataObject){ 

    // when deserializing to MyDataObject it thorows above error 
    //Handle logic 
    } 

客戶端代碼片斷

var myDataObject= { 
    "testCases": [$scope.bug.TestCaseVO], 
    "userName":userName} 

angularJsMyService.Bug.attachBug({},myDataObject) 
           .$promise.then(function(data){ 
    ... 
    } 

我的問題是,我怎麼能之前,傑克遜使用傑克遜的mixin上REST方法的參數反序列化them.Appreciate任何幫助。

回答

1

我想你可能沒有把傑克遜和澤西島以正確的方式整合在一起。退房Jersey’s doc on Jackson。在你的項目中,應該有一個實施ContextResolver<ObjectMapper>的課程。 Jersey的REST端點使用此類中由getContext(Class<?> type)返回的ObjectMapper實例。您可以使用Mix-in配置ObjectMapper

相關問題