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

Mixin with @JsonProperry to override @JsonIgnore no longer works in 2.14 #3812

Closed
ddewaele opened this issue Mar 7, 2023 · 5 comments
Closed

Comments

@ddewaele
Copy link

ddewaele commented Mar 7, 2023

Given the following code

public class MixinSample {

    public static class CustomerMixin {
        @JsonProperty
        public String id;
    }

    public static void main(String[] args) throws Exception {
        Customer customer = new Customer();
        customer.setId("123");   // This POJO has a JsonIgnore on the id field
        customer.setName("Joe");

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.addMixIn(Customer.class, CustomerMixin.class);
        System.out.println("objectMapper = " + objectMapper.writeValueAsString(customer));

    }
}

With jackson-databind 2.13.x it outputs as expected (Mixin overrides the JsonIgnore id field):

{"id":"123","name":"Joe"}

With jackson-databind 2.14.x it doesn't seem to take into account the mixin :

{"name":"Joe"}
@ddewaele ddewaele added the to-evaluate Issue that has been received but not yet evaluated label Mar 7, 2023
@cowtowncoder
Copy link
Member

Incomplete reproduction, would need Customer definition too.

But assuming there's simple @JsonIgnore on property id (on setId() or getId()), the problem is that @JsonProperty does not exactly override @JsonIgnore: the two are in conflict.
To override ignoral, one has to add mix-in for

 @JsonIgnore(false)

and not add conflicting @JsonProperty. Adding override as above should have worked with 2.13 and earlier as well.
I think the fix via #3357 is what you are seeing here.

Older behavior (of @JsonProperty having precedence if both included) was unintended, as in case of ignore-and-property, ignoral should have (had) precedence.

New behavior is correct, at any rate.

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Mar 7, 2023
@ddewaele
Copy link
Author

ddewaele commented Mar 7, 2023

Correct. Thx for the clarification. Closing Issue.

@ddewaele ddewaele closed this as completed Mar 7, 2023
@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 7, 2023

Forgot to say: thank you for filing this @ddewaele.

FWTW, this is mentioned in 2.14 release notes:

https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.14

(under "Observed/Reported changes" section)

and reported as #3722 earlier (which I forgot initially)

@ddewaele
Copy link
Author

ddewaele commented Mar 7, 2023

Thx again for clarifying. We're doing a big Spring boot 2.x -> 3.x upgrade on a lot of projects and I did read in the Jackson 2.14 release notes initially but somehow missed this one.

Awesome work you people are doing in keeping this great library compatible too a large degree for such a long time !

@cowtowncoder
Copy link
Member

@ddewaele Actually it is quite possible that that note was added after release -- so you couldn't have seen it then. I just added note here for sake of completness (was about to add something there if this was missing).

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

2 participants