-
-
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
7b6d91d
commit 92718cf
Showing
3 changed files
with
100 additions
and
2 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
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
60 changes: 60 additions & 0 deletions
60
src/test/java/com/fasterxml/jackson/databind/deser/filter/ProblemHandler3450Test.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,60 @@ | ||
package com.fasterxml.jackson.databind.deser.filter; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
|
||
public class ProblemHandler3450Test extends BaseMapTest | ||
{ | ||
// [databind#3450] | ||
|
||
static class LenientDeserializationProblemHandler extends DeserializationProblemHandler { | ||
|
||
@Override | ||
public Object handleWeirdStringValue(DeserializationContext ctxt, Class<?> targetType, String valueToConvert, | ||
String failureMsg) throws IOException { | ||
|
||
// I just want to ignore badly formatted value | ||
return null; | ||
} | ||
} | ||
|
||
static class TestPojo3450Int { | ||
public Integer myInteger; | ||
} | ||
|
||
static class TestPojo3450Long { | ||
public Long myLong; | ||
} | ||
|
||
private final ObjectMapper LENIENT_MAPPER = | ||
JsonMapper.builder().addHandler(new LenientDeserializationProblemHandler()).build(); | ||
|
||
public void testIntegerCoercion3450() throws Exception | ||
{ | ||
TestPojo3450Int pojo; | ||
|
||
// First expected coercion into `null` from empty String | ||
pojo = LENIENT_MAPPER.readValue("{\"myInteger\" : \"\"}", TestPojo3450Int.class); | ||
assertNull(pojo.myInteger); | ||
|
||
// and then coercion into `null` by our problem handler | ||
pojo = LENIENT_MAPPER.readValue("{\"myInteger\" : \"notInt\"}", TestPojo3450Int.class); | ||
assertNull(pojo.myInteger); | ||
} | ||
|
||
public void testLongCoercion3450() throws Exception | ||
{ | ||
TestPojo3450Long pojo; | ||
|
||
// First expected coercion into `null` from empty String | ||
pojo = LENIENT_MAPPER.readValue("{\"myLong\" : \"\"}", TestPojo3450Long.class); | ||
assertNull(pojo.myLong); | ||
|
||
// and then coercion into `null` by our problem handler | ||
pojo = LENIENT_MAPPER.readValue("{\"myLong\" : \"notSoLong\"}", TestPojo3450Long.class); | ||
assertNull(pojo.myLong); | ||
} | ||
} |