-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix #4994 CoercionConfig
for CoercionAction.AsNull
not working on empty array deserialization
#4999
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a85bf92
fix #4994 Add coercionConfig handling
JooHyukKim b3592a9
Leave only with AsNull
JooHyukKim 89f450f
Rename emptyArray handling
JooHyukKim 1131acd
Remove null check for String[] coercion
JooHyukKim 833c0fd
Merge branch '2.18' into 4994-2
JooHyukKim 958bea1
Add case for object and pojo array deserializer
JooHyukKim d8f5676
Rename test objects
JooHyukKim c4ce6a1
Update VERSION-2.x
JooHyukKim b9cf2f4
Modify test names
JooHyukKim 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 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
37 changes: 37 additions & 0 deletions
37
src/test/java/com/fasterxml/jackson/databind/convert/CoerceEmptyArrayAsNull4994Test.java
This file contains 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,37 @@ | ||
package com.fasterxml.jackson.databind.convert; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.cfg.CoercionAction; | ||
import com.fasterxml.jackson.databind.cfg.CoercionInputShape; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
// [databind#4994] CoercionConfig for empty arrays not working as expected | ||
public class CoerceEmptyArrayAsNull4994Test | ||
extends DatabindTestUtil | ||
{ | ||
public static class Pojo4994 { | ||
public String[] value; | ||
} | ||
|
||
@Test | ||
public void testAsNull() | ||
throws Exception | ||
{ | ||
final ObjectMapper MAPPER_TO_NULL = jsonMapperBuilder() | ||
.withCoercionConfigDefaults(cfg -> | ||
cfg.setCoercion(CoercionInputShape.EmptyArray, CoercionAction.AsNull)) | ||
.build(); | ||
|
||
String json = "{\"value\": []}"; | ||
|
||
Pojo4994 pojo = MAPPER_TO_NULL.readValue(json, Pojo4994.class); | ||
|
||
assertNull(pojo.value); // expected: <null> but was: <[]> | ||
} | ||
|
||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can never be
null
, let's remove check.