-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
093cdcb
commit b66dfb6
Showing
2 changed files
with
70 additions
and
5 deletions.
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
61 changes: 61 additions & 0 deletions
61
src/test-jdk14/java/com/fasterxml/jackson/databind/RecordWithJsonSetter2974Test.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,61 @@ | ||
package com.fasterxml.jackson.databind; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.annotation.Nulls; | ||
import com.fasterxml.jackson.databind.RecordTest.RecordWithRename; | ||
import com.fasterxml.jackson.databind.exc.InvalidNullException; | ||
|
||
public class RecordWithJsonSetter2974Test extends BaseMapTest | ||
{ | ||
record RecordWithNonNullDefs(@JsonSetter(nulls=Nulls.AS_EMPTY) List<String> names, | ||
@JsonSetter(nulls=Nulls.FAIL) Map<String, Integer> agesByNames) | ||
{ } | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods, Record type introspection | ||
/********************************************************************** | ||
*/ | ||
|
||
// [databind#2974] | ||
public void testDeserializeWithNullAsEmpty() throws Exception | ||
{ | ||
final ObjectReader r = MAPPER.readerFor(RecordWithNonNullDefs.class); | ||
// First, regular case | ||
RecordWithNonNullDefs value = r.readValue(a2q( | ||
"{'names':['bob'],'agesByNames':{'bob':39}}")); | ||
assertEquals(1, value.names().size()); | ||
assertEquals("bob", value.names().get(0)); | ||
assertEquals(1, value.agesByNames().size()); | ||
assertEquals(Integer.valueOf(39), value.agesByNames().get("bob")); | ||
|
||
// Then leave out list | ||
value = r.readValue(a2q("{'agesByNames':{'bob':42}}")); | ||
assertNotNull(value.names()); | ||
assertEquals(0, value.names().size()); | ||
assertNotNull(value.agesByNames()); | ||
assertEquals(1, value.agesByNames().size()); | ||
assertEquals(Integer.valueOf(42), value.agesByNames().get("bob")); | ||
|
||
assertEquals(new RecordWithRename(123, "Bob"), value); | ||
} | ||
|
||
// [databind#2974] | ||
public void testDeserializeWithFailForNull() throws Exception | ||
{ | ||
final ObjectReader r = MAPPER.readerFor(RecordWithNonNullDefs.class); | ||
// First, regular case | ||
// But attempting to leave out Map ought to fail | ||
try { | ||
/*RecordWithNonNullDefs value =*/ r.readValue(a2q("{'names':['bob']}")); | ||
fail("Should not pass with missing/null 'agesByNames'"); | ||
} catch (InvalidNullException e) { | ||
verifyException(e, "property \"agesByNames\""); | ||
} | ||
} | ||
} |