Skip to content

feat(#1381): Add a way to specify "inject-only" with @JacksonInject #5175

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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

giulong
Copy link
Contributor

@giulong giulong commented May 24, 2025

useInput=TRUE in JacksonInject now make deserialization discard the injected value in favor of input (if any)

…lization discard the injected value in favor of input (if any)
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.databind.tofix;
package com.fasterxml.jackson.databind.deser.inject;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved since this should not fail anymore

}

@Test
@DisplayName("input YES, injectable YES, useInput DEFAULT|FALSE => injected")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to useInput's javadocs:

Default is OptBoolean.DEFAULT, which translates to OptBoolean.TRUE: this is
for backwards compatibility (2.8 and earlier always allow binding input value).

This combination: input YES, injectable YES, useInput DEFAULT should actually behave as if we had useInput = TRUE, that is dropping the injected value and returning the input.

Nevertheless, since useInput never worked that way, this would mean introducing breaking changes. My suggestion is to keep things as per this test and change the javadoc accordingly:

Default is OptBoolean.DEFAULT, which translates to OptBoolean.FALSE

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class JacksonInject1381WithOptionalTest extends DatabindTestUtil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class shows how the behavior changes for all the combinations of the other test class when all injected fields are optional. Do you think we still need a required property in the annotation?

I feel like combining useInput and optional would cover all cases, also because optional should drive the same logic (but reversed) of required. Given this, adding a required property would make things unclear for the users, and the internal logic would be quite messy. Does this make sense?

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

Successfully merging this pull request may close these issues.

1 participant