-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Ignore Records' immutable fields in BeanDeserializerFactory instead of ignoring it in POJOPropertiesCollector, to preserve any annotation info the fields may be carrying. #4627
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
Merged
cowtowncoder
merged 7 commits into
FasterXML:2.18
from
yihtserns:records-desered-jsonignore
Jul 21, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1b1078
Add test cases to verify that Records' deserialization will ignore a …
yihtserns 2096c42
Add test cases to demonstrate that deserialization is not ignoring a …
yihtserns 2b4cf9f
Ignore Records' immutable fields in BeanDeserializerFactory instead o…
yihtserns 2ce22e3
Add test cases to demonstrate that serialization is not ignoring a pr…
yihtserns 7a46880
Merge branch '2.18' into records-desered-jsonignore
cowtowncoder 8eb2f55
Change the way (immutable) Record field is dropped
cowtowncoder ae1083d
Update release notes
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -434,13 +434,7 @@ protected void collectAll() | |
| // First: gather basic accessors | ||
| LinkedHashMap<String, POJOPropertyBuilder> props = new LinkedHashMap<String, POJOPropertyBuilder>(); | ||
|
|
||
| // 15-Jan-2023, tatu: [databind#3736] Let's avoid detecting fields of Records | ||
| // altogether (unless we find a good reason to detect them) | ||
| // 17-Apr-2023: Need Records' fields for serialization for cases | ||
| // like [databind#3628], [databind#3895] and [databind#3992] | ||
| if (!isRecordType() || _forSerialization) { | ||
| _addFields(props); // note: populates _fieldRenameMappings | ||
| } | ||
| _addFields(props); // note: populates _fieldRenameMappings | ||
| _addMethods(props); | ||
| // 25-Jan-2016, tatu: Avoid introspecting (constructor-)creators for non-static | ||
| // inner classes, see [databind#1502] | ||
|
|
@@ -1301,10 +1295,7 @@ protected void _removeUnwantedProperties(Map<String, POJOPropertyBuilder> props) | |
| */ | ||
| protected void _removeUnwantedAccessor(Map<String, POJOPropertyBuilder> props) | ||
| { | ||
| // 15-Jan-2023, tatu: Avoid pulling in mutators for Records; Fields mostly | ||
| // since there should not be setters. | ||
| final boolean inferMutators = !isRecordType() | ||
| && _config.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS); | ||
| final boolean inferMutators = _config.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
| Iterator<POJOPropertyBuilder> it = props.values().iterator(); | ||
|
|
||
| while (it.hasNext()) { | ||
|
|
||
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
45 changes: 45 additions & 0 deletions
45
...t-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithOverriddenAccessorTest.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,45 @@ | ||
| package com.fasterxml.jackson.databind.records; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import com.fasterxml.jackson.annotation.JsonIncludeProperties; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class RecordWithOverriddenAccessorTest extends DatabindTestUtil { | ||
|
|
||
| record Id2Name(int id, String name) { | ||
| } | ||
|
|
||
| record RecordWithJsonIncludeProperties(@JsonIncludeProperties("id") Id2Name child) { | ||
| @Override | ||
| public Id2Name child() { | ||
| return child; | ||
| } | ||
| } | ||
|
|
||
| record RecordWithJsonIgnoreProperties(@JsonIgnoreProperties("name") Id2Name child) { | ||
| @Override | ||
| public Id2Name child() { | ||
| return child; | ||
| } | ||
| } | ||
|
|
||
| private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
|
||
| // [databind#4630] | ||
| @Test | ||
| public void testSerializeJsonIncludeProperties() throws Exception { | ||
| String json = MAPPER.writeValueAsString(new RecordWithJsonIncludeProperties(new Id2Name(123, "Bob"))); | ||
| assertEquals(a2q("{'child':{'id':123}}"), json); | ||
| } | ||
|
|
||
| // [databind#4630] | ||
| @Test | ||
| public void testSerializeJsonIgnoreProperties() throws Exception { | ||
| String json = MAPPER.writeValueAsString(new RecordWithJsonIgnoreProperties(new Id2Name(123, "Bob"))); | ||
| assertEquals(a2q("{'child':{'id':123}}"), json); | ||
| } | ||
| } |
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.