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

@JsonIgnoreProperties does not prevent Exception Conflicting getter/setter definitions for property #426

Closed
gmkll opened this issue Mar 20, 2014 · 7 comments

Comments

@gmkll
Copy link

gmkll commented Mar 20, 2014

The use case is a base class which I could not change and I want to ignore the conflicting property (putting JsonIgnoreProperties in a child class). Should the JsonIgnoreProperties not prevent this exception?? This occurs in this simplified test scenario:

The Mapping class:

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties({ "userId"})
public class User {
 Integer userId; 

    void setUserId(String id) {
        setUserId(new Integer(id));
    };

    public Integer getUserId() 
    {
        return userId;
    }

    public void setUserId(Integer v)
    {
        this.userId = v;
    }
}

The Test:

    @Test
    public void testDeSerObject() throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        JsonIgnoreProperties ignore = User.class.getAnnotation(JsonIgnoreProperties.class);
        System.out.println("ignore:,"+ ignore);
        String jsonString = "{id: 9, firstName: \"Mike\" }";
        User result = mapper.reader( User.class ).readValue(jsonString);
        System.out.println("result:"+ result.getUserId());
    }

This fails with Exception (cause) message:

Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property "userId": org.apache.fulcrum.json.jackson.User#setUserId(1 params) vs org.apache.fulcrum.json.jackson.User#setUserId(1 params)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:222)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getMutator(POJOPropertyBuilder.java:295)
    at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findBackReferenceProperties(BasicBeanDescription.java:368)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addReferenceProperties(BeanDeserializerFactory.java:641)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:271)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:401)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:354)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:267)
@cowtowncoder
Copy link
Member

Interesting. Yes, I see the problem here. There are some other related problems with conflict detection (false alarms), but this is bit different.

cowtowncoder added a commit that referenced this issue May 15, 2014
@cowtowncoder
Copy link
Member

Ok. One problem is that info on properties to ignore is not yet available at point in code. But, on the other hand, this particular code path should not quite require full resolution. Will see if I can work around it.

@cowtowncoder
Copy link
Member

Damn. Explicitly named ignorals are accessible by BasicBeanDescription, but not class annotations...

@jharen
Copy link

jharen commented Dec 1, 2015

I, too am hitting this issue with jackson-databind 2.6.3. When I try to scan classes from Amazon's com.amazonaws.services.cloudformation.model package, some fail. An example is the com.amazonaws.services.cloudformation.model.Stack class, which defines:

private String stackStatus;
...
public void setStackStatus(String stackStatus) {
    this.stackStatus = stackStatus;
}

public void setStackStatus(StackStatus stackStatus) {
    this.stackStatus = stackStatus.toString();
}

Since this class comes from a third-party library, right now my only recourse is to create a proxy factory that produces objects with only one setter for any given property, which is pretty tedious.

@cowtowncoder
Copy link
Member

Yes,this is unfortunate. If it was easy to fix, it would have, but I hope a solution will be eventually found.

@jharen
Copy link

jharen commented Dec 2, 2015

Oh, for sure. Not a complaint, just logging another data point. I appreciate all the work you guys put in.

cowtowncoder added a commit that referenced this issue Dec 22, 2015
@cowtowncoder cowtowncoder added 2.10 and removed 2.9 labels Sep 12, 2019
@cowtowncoder cowtowncoder added 2.12 and removed 2.10 labels Apr 12, 2020
@cowtowncoder
Copy link
Member

Looks like this actually works with 2.12, related to other changes I think. At least I can not reproduce the issue with simple changes here.

Also of note: #1044 added a way to resolve issues as well (included in 2.7).

@cowtowncoder cowtowncoder changed the title JsonIgnoreProperties does not prevent Exception Conflicting getter/setter definitions for property @JsonIgnoreProperties does not prevent Exception Conflicting getter/setter definitions for property Jul 11, 2020
cowtowncoder added a commit that referenced this issue Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants