2017-11-08 1 views
0

와 DeserializationContext의 변수처럼 선언 :스토어 내가 MyClass에 대한 사용자 정의 JSON 디시리얼라이저를 저지

@JsonDeserialize(using=MyClassDeserializer.class) 
public class MyClass { 
... 

와 정의 그리고

public class MyClassDeserializer extends JsonDeserializer<MyClass> { 

    @Override 
    public MyClass deserialize(JsonParser jsonParser, DeserializationContext ctxt) { 
    ... 

로, 나는 전화를 저지 클라이언트 객체를 사용 웹 서비스 및 MyClass의 인스턴스로 JSON 변환은 :

ClientConfig clientConfig = new DefaultClientConfig(); 
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); 
Client httpClient = Client.create(clientConfig); 

WebResource webResource = httpClient.resource("theUrl"); 
ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class); 
... 

MyClass myClass = response.getEntity(MyClass.class); 

내 질문은 이것이다 : STO에 I를 어떻게 DeserializationContext의 변수를 다시?

나는 Pass a field to custom deserializer class Jackson을 보았지만 명시 적으로 매퍼를 작성하지는 않습니다.

Long value = (Long) ctxt.findInjectableValue("abc", null, null); 

그리고 이것은 호출하기 전에 클라이언트 생성 :

ObjectMapper mapper = new ObjectMapper(); 
mapper.setInjectableValues(newInjectableValues()); 
JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider(); 
jacksonProvider.setMapper(mapper); 
clientConfig.getSingletons().add(jacksonProvider); 

답변

0

이이 역 직렬화하는 방법이를 추가하여 작업을 얻었다
관련 문제