-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
giulong
wants to merge
50
commits into
FasterXML:2.x
Choose a base branch
from
giulong:feature/databind-1381-inject-only
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+795
−25
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9a42cca
feat(#1381): useInput=TRUE in JacksonInject now make deserialization …
giulong d714aeb
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder d6bee5f
Change exception throws
cowtowncoder bc094d8
...
cowtowncoder a12a3d7
Add release notes; broke tests by changing annotation placements
cowtowncoder 69c603e
test: minor refactor to apply coding conventions
giulong 191292c
test(#1381): covering all cases for JacksonInject, whether we useInpu…
giulong 5705aff
feat(#1381): JacksonInject.useInput works for constructor properties …
giulong bc9d37e
Merge branch '2.x' into feature/databind-1381-inject-only
giulong 272c499
Merge branch 'FasterXML:2.x' into feature/databind-1381-inject-only
giulong 5da46ac
test(#1381): minor code cleaning removing unused getters
giulong deb1741
feat(#1381): always adding properties annotated with JacksonInject to…
giulong bf34e81
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder fac9b19
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 13715a3
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 03ba2cf
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 8423113
Add back accidentally removed CREDITS line (merge)
cowtowncoder 98abe58
...
cowtowncoder 402e3cb
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder bd2c4d7
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 0c2f3f3
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 202e5ec
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder e30140b
Test cleanup for easier 3.0 merging
cowtowncoder 2da95a7
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 350f959
Minor renaming
cowtowncoder 1e8578d
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 32e84cb
Merge branch '2.x' into feature/databind-1381-inject-only
giulong 5c58665
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 5d32825
refactor(#1381): changing exception message in ValueInjector when no …
giulong 285989f
chore(#1381): minor comment update
giulong eaf80fd
fix(#1381): avoid duplicate injection on constructor properties
giulong be8aea6
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder a559e93
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 6abb36e
Minor javadoc fix
cowtowncoder 45fa152
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder d258595
Fix name reference
cowtowncoder 648b4bc
Improve test to verify injection field name
cowtowncoder e4f8d7d
Remove unnecessary diff
cowtowncoder 807b6af
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 8f905d8
Fix a bug
cowtowncoder 8d76609
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 6be9d07
Add parentheses for clarity
cowtowncoder 193047f
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 4defc99
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 626e3c8
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder 0726035
Optimize tracking of injectable values
cowtowncoder 0e780c0
...
cowtowncoder 0991a05
...
cowtowncoder e18f0a3
...
cowtowncoder 807771e
Merge branch '2.x' into feature/databind-1381-inject-only
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
...ml/jackson/databind/deser/inject/JacksonInject1381DeserializationFeatureDisabledTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| package com.fasterxml.jackson.databind.deser.inject; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.annotation.OptBoolean; | ||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| import com.fasterxml.jackson.databind.InjectableValues; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.exc.ValueInstantiationException; | ||
| import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| class JacksonInject1381DeserializationFeatureDisabledTest extends DatabindTestUtil { | ||
| static class InputDefault { | ||
| @JacksonInject(value = "key") | ||
| @JsonProperty("field") | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputDefault(@JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
| } | ||
|
|
||
| static class InputDefaultConstructor { | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputDefaultConstructor(@JacksonInject(value = "key") | ||
| @JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
| } | ||
|
|
||
| static class InputTrue { | ||
| @JacksonInject(value = "key", useInput = OptBoolean.TRUE) | ||
| @JsonProperty("field") | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputTrue(@JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
| } | ||
|
|
||
| static class InputTrueConstructor { | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputTrueConstructor(@JacksonInject(value = "key", useInput = OptBoolean.TRUE) | ||
| @JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| static class InputFalse { | ||
| @JacksonInject(value = "key", useInput = OptBoolean.FALSE) | ||
| @JsonProperty("field") | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputFalse(@JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
| } | ||
|
|
||
| static class InputFalseConstructor { | ||
| private final String _field; | ||
|
|
||
| @JsonCreator | ||
| public InputFalseConstructor(@JacksonInject(value = "key", useInput = OptBoolean.FALSE) | ||
| @JsonProperty("field") final String field) { | ||
| _field = field; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return _field; | ||
| } | ||
| } | ||
|
|
||
| private final String empty = "{}"; | ||
| private final String input = "{\"field\": \"input\"}"; | ||
|
|
||
| private final ObjectMapper plainMapper = jsonMapperBuilder() | ||
| .disable(DeserializationFeature.FAIL_ON_UNKNOWN_INJECT_VALUE) | ||
| .build(); | ||
| private final ObjectMapper injectedMapper = jsonMapperBuilder() | ||
| .injectableValues(new InjectableValues.Std().addValue("key", "injected")) | ||
| .disable(DeserializationFeature.FAIL_ON_UNKNOWN_INJECT_VALUE) | ||
| .build(); | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input NO, injectable NO, useInput DEFAULT|TRUE|FALSE => exception") | ||
| void test1() { | ||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputDefault.class)); | ||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputDefaultConstructor.class)); | ||
|
|
||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputTrue.class)); | ||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputTrueConstructor.class)); | ||
|
|
||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputFalse.class)); | ||
| assertThrows(ValueInstantiationException.class, | ||
| () -> plainMapper.readValue(empty, InputFalseConstructor.class)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input NO, injectable YES, useInput DEFAULT|TRUE|FALSE => injected") | ||
| void test2() throws Exception { | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputDefault.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputDefaultConstructor.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputTrue.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputTrueConstructor.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputFalse.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(empty, InputFalseConstructor.class).getField()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable NO, useInput DEFAULT|FALSE => exception") | ||
| void test3() throws Exception { | ||
| assertEquals("input", plainMapper.readValue(input, InputDefault.class).getField()); | ||
| assertEquals("input", plainMapper.readValue(input, InputDefaultConstructor.class).getField()); | ||
| assertEquals("input", plainMapper.readValue(input, InputFalse.class).getField()); | ||
| assertEquals("input", plainMapper.readValue(input, InputFalseConstructor.class).getField()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable NO, useInput TRUE => input") | ||
| void test4() throws Exception { | ||
| assertEquals("input", plainMapper.readValue(input, InputTrue.class).getField()); | ||
| assertEquals("input", plainMapper.readValue(input, InputTrueConstructor.class).getField()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable YES, useInput DEFAULT|FALSE => injected") | ||
| void test5() throws Exception { | ||
| assertEquals("injected", injectedMapper.readValue(input, InputDefault.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(input, InputDefaultConstructor.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(input, InputFalse.class).getField()); | ||
| assertEquals("injected", injectedMapper.readValue(input, InputFalseConstructor.class).getField()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("FAIL_ON_UNKNOWN_INJECT_VALUE NO, input YES, injectable YES, useInput TRUE => input") | ||
| void test6() throws Exception { | ||
| assertEquals("input", injectedMapper.readValue(input, InputTrue.class).getField()); | ||
| assertEquals("input", injectedMapper.readValue(input, InputTrueConstructor.class).getField()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.