Hi All,

I have written a custom de-serializer to ensure backward compatibility 
between models and applied it on a field as below. I want the de-serializer 
to kick-in if the JsonNode is array otherwise I want the default 
deserializer to deserialize the field. I tried the below approach using the 
ObjectMapper object but it is not working.

class Person {

    private int id;

   @JsonDeserialize(using = CustomDeserializer.class)
   @JsonAlias("addresses")
    private AddressDetails addressDetails;
     // .Getter setters 
}

but in *else* part jsonNode.asText() is returning empty string, but 
debugger is showing child nodes. am I doing something wrong here?

@Override
public AddressDetails deserialize(...) {

    AddressDetails addressDetails = new AddressDetails();
    JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
   AddressDetails addressDetails = null;
    if(jsonNode.isArray()) {
        // construct AddressDetails object
    }
    else {
        ObjectMapper objectMapper = new ObjectMapper();
        addressDetails = objectMapper.readValue(jsonNode.asText(), 
AddressDetails.class);
     }
     return addressDetails;
}

Thanks
Govinda

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/40c5f745-ad0a-43b9-9e3c-5753d44ca379n%40googlegroups.com.

Reply via email to