-
-
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
a8e7cdf
commit dcfb0cc
Showing
3 changed files
with
65 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
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
45 changes: 45 additions & 0 deletions
45
src/test/java/com/fasterxml/jackson/databind/filter/ProblemHandler1767Test.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,45 @@ | ||
package com.fasterxml.jackson.databind.filter; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; | ||
|
||
public class ProblemHandler1767Test extends BaseMapTest | ||
{ | ||
static class IntHandler | ||
extends DeserializationProblemHandler | ||
{ | ||
@Override | ||
public Object handleWeirdStringValue(DeserializationContext ctxt, | ||
Class<?> targetType, | ||
String valueToConvert, | ||
String failureMsg) | ||
{ | ||
if (targetType != Integer.TYPE) { | ||
return NOT_HANDLED; | ||
} | ||
return 1; | ||
} | ||
} | ||
|
||
static class TestBean { | ||
int a; | ||
|
||
public int getA() { | ||
return a; | ||
} | ||
|
||
public void setA(int a) { | ||
this.a = a; | ||
} | ||
|
||
} | ||
|
||
public void testPrimitivePropertyWithHandler() throws Exception { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
mapper.addHandler(new IntHandler()); | ||
TestBean result = mapper.readValue(aposToQuotes("{'a': 'not-a-number'}"), TestBean.class); | ||
assertNotNull(result); | ||
assertEquals(1, result.a); | ||
} | ||
|
||
} |