Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicting Getter Definitions for Different List Properties with Same Element as Content (dup of #27) #656

Closed
evoelise opened this issue Jun 4, 2024 · 4 comments
Labels
duplicate Issue is duplicate of another issue

Comments

@evoelise
Copy link

evoelise commented Jun 4, 2024

Apologies for the severe redaction in code examples & reported errors.

I am getting the following exception with Jackson v2.13.4:

org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.xxxx.Message];
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Conflicting getter definitions for property "Client": com.xxxx.Message#getSentByClients()
vs com.xxxx.Message#getReceivedByClients() (through reference chain: java.util.ArrayList[0])
            at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:462)
            at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104)

It should be possible to have XML that contains different named list elements that contain the same named list items, for example:

<Message>

  <sent_by_clients>
    <client>client_1</client>
    <client>client_2</client>
    <client>client_3</client>
  </sent_by_clients>

  <received_by_clients>
    <client>client_4</client>
    <client>client_5</client>
    <client>client_6</client>
  </received_by_clients>

</Message>

To this end I have set up something similar to the following Java code:

@XmlRootElement(name="Message")
@JsonInclude(Include.NON_NULL)
public class Message {

            private List<Client> sentByClients;
            private List<Client> receivedByClients;

            @JacksonXmlElementWrapper(localName = "sent_by_clients")      
            @JacksonXmlProperty(localName = "client")    
            @JsonProperty("sent_by_clients")
            public List<Client> getSentByClients() {
                        return sentByClients;
            }

            public void setSentByClients(List<WebClient> aSentByClients) {
                        sentByClients = aSentByClients;
            }

            @JacksonXmlElementWrapper(localName = "received_by_clients")
            @JacksonXmlProperty(localName = "client")    
            @JsonProperty("received_by_clients")
            public List<Client> getReceivedByClients() {
                        return receivedByClients;
            }

            public void setReceivedByClients(List<WebClient> aReceivedByClients) {
                        receivedByClients = aReceivedByClients;
            }
}

I believe this should work - but if we do this we get an error stating the there are conflicting getter definitions even though the getters are for different list properties. Should the libraries realise that even though the same named JacksonXmlProperty are used these are part of different elements due to the different named JacksonXmlElementWrappers?

Am I correct that this should work and this is an issue - or am I missing something and I should code or annotate this in a different way?

@cowtowncoder
Copy link
Member

Wrong repo, will move.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-core Jun 4, 2024
@cowtowncoder
Copy link
Member

cowtowncoder commented Jun 4, 2024

This should work, but unfortunately due to implementation details, "inner" element name is used as a key leading to the problem. So while wrapper names differ, they are not used for fetching property information.
I think there is probably an issue here already... I think #27 is same as this one.

I am not sure there is a work-around available, unfortunately.

@evoelise
Copy link
Author

evoelise commented Jun 4, 2024

@cowtowncoder Thanks for moving to the correct repo & your answer. Also I can confirm it looks like the same issue as #27. I did search for the issue but didn't find it when I looked.
It's not encouraging that #27 has been open since 2012 but I am happy for this to be closed as a duplicate.

@cowtowncoder
Copy link
Member

Yes, it is unfortunate one and there is no work on-going to resolve it (PRs welcome as usual, but aside).
Closing as dup of #27.

@cowtowncoder cowtowncoder changed the title Conflicting Getter Definitions for Different List Properties with Same Element as Content Conflicting Getter Definitions for Different List Properties with Same Element as Content (dup of #27) Jun 4, 2024
@cowtowncoder cowtowncoder added the duplicate Issue is duplicate of another issue label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issue is duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants