FasterXML / jackson-module-jaxb-annotations

(DEPRECATED!!!) Moved to: https://github.com/FasterXML/jackson-modules-base/
https://github.com/FasterXML/jackson-modules-base
44 stars 20 forks source link

Conflicting getter definitions Exception #42

Closed haribachala closed 6 years ago

haribachala commented 9 years ago

Hi when two properties having Different @XmlElementWrapper names and same @XmlElement name then exception occurring.

Exception: Caused by: java.lang.IllegalArgumentException: Conflicting getter definitions for property "Address" example:

List<Address>  officeAddresses;
List<Address>  residenceAddresses;

    @XmlElement(name="Address")
    public List<Address> getResidenceAddresses() {
        return residenceAddresses;
    }

    @XmlElementWrapper(name="ResidenceAddress")
    public void setResidenceAddress(List<Address> residenceAddress) {
    this.residenceAddress= residenceAddress;
    }

    @XmlElement(name="Address")
    public List<Address> getOfficeAddresses() {
        return officeAddresses;
    }

    @XmlElementWrapper(name="OfficeAddress")
    public void setOfficeAddress(List<Address> officeAddresses) {
        this.officeAddresses= officeAddresses;
    }

How to handle this kind of things ?

eg:

<officeAddress>
     <address>
</officeAddress>

<residenceAddress>
   <address>
</residenceAddress>

Not able create JSON Response for Above cases using Jackson.

Jettison working fine for above kind of issues.

cowtowncoder commented 9 years ago

Correct, this causes conflict currently because wrapper handling/resolution occurs at a later point, after duplicate checking. It is a problem.

haribachala commented 9 years ago

Thanks,

is there any work around will suggest to come out of this problem. the above code working with 1.9 version of Jackson.

cowtowncoder commented 9 years ago

Unfortunately I am not aware of a work-around for this problem.

haribachala commented 9 years ago

The following Workaround will work for conflict issue.

godgav commented 9 years ago

I've found a workaround for this issue

List<Address>  officeAddresses;
List<Address>  residenceAddresses;
    @XmlElementWrapper(name="ResidenceAddress")
    @XmlElements(@XmlElement(name="Address"))
    public List<Address> getResidenceAddresses() {
        return residenceAddresses;
    }

    @XmlElementWrapper(name="OfficeAddress")
    @XmlElements(@XmlElement(name="Address"))
    public List<Address> getOfficeAddresses() {
        return officeAddresses;
    }
cowtowncoder commented 9 years ago

@godgav Thank you for sharing your workaround.

ghost commented 8 years ago

@godgav +1 for the workaround :)

I found I needed a little more meta before I got closer to what I needed:

@JsonProperty("outstandingProofs")
@XmlElementWrapper(name = "outstandingProofs")
@XmlElements(@XmlElement(name = "proof", type = TypeOneProofRequirement.class))
public List<ProofRequirement> getTypeOneProofs() {
    return proofs;
}

Consumes this:

<outstandingProofs>
    <proof>
        <!-- ... -->
    </proof>
</outstandingProofs>

Produces this:

"outstandingProofs" : [ {
  "proof" : {
    ...
  }
} ]
cowtowncoder commented 6 years ago

Project has moved, so although I think problem exists in some form, would need to be re-filed at:

https://github.com/FasterXML/jackson-modules-base/issues