0

I am attempting to deserialize a JSON sent from a REST application. This object needs to be deserialized into a 3rd party object that contains polymorphic methods. When I attempt to do the deserialization using jackson I get the following exception:

Conflicting setter definitions for property "system": ca.uhn.fhir.model.dstu2.composite.CodingDt#setSystem(1 params) vs ca.uhn.fhir.model.dstu2.composite.CodingDt#setSystem(1 params)

public CodingDt setSystem(UriDt theValue) {
    mySystem = theValue;
    return this;
}

public CodingDt setSystem( String theUri) {
    mySystem = new UriDt(theUri); 
    return this; 
}

I cannot modify the 3rd party class so used the Jackson MixIn as described in the ticket Jackson Mixin.This approach seems to work but there are many classes that this class refers to, that has the same exact problem. If I need to add a MixIn for each class, then I am ending up with a large number of MixIn's which is making the code less readable and hard to maintain.

Is there any global setting in Jackson that I can set, so that only one of the setters is used, or a setting to provide additional info to the deserailizer so that it does not complain.

Community
  • 1
  • 1
  • Have try deserialisation using fields instead of setters? Something like this https://gist.github.com/bhdrkn/d53f15858dd304b33542 – bhdrkn Jun 15 '15 at 06:14
  • I cannot use fields as the field name is different to the getter/setter. – pradeep vemulakonda Jun 15 '15 at 12:31
  • If your only concern is about field name, you may try both using fields and a propertyNamingStrategy and map existing fields with your liking. Here an example for PropertyNamingStrategy, http://www.javaroots.com/2013/03/how-to-use-naming-in-jackson.html – bhdrkn Jun 15 '15 at 12:48
  • 1
    I think thats what I want.Thank you – pradeep vemulakonda Jun 16 '15 at 05:56

1 Answers1

0

I have use the PropertyNamingStrategy for Jackson as described in http://www.javaroots.com/2013/03/how-to-use-naming-in-jackson.html. Thanks to @bhdrkn

I also have to use the following code to ignore unknown properties for my code to work.

ObjectMapper objectMapper = getObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);