-
-
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
b66dfb6
commit 7fd0af3
Showing
4 changed files
with
59 additions
and
4 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
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
56 changes: 56 additions & 0 deletions
56
src/test/java/com/fasterxml/jackson/databind/deser/filter/ProblemHandler2973Test.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,56 @@ | ||
package com.fasterxml.jackson.databind.deser.filter; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; | ||
import com.fasterxml.jackson.databind.exc.MismatchedInputException; | ||
|
||
public class ProblemHandler2973Test extends BaseMapTest | ||
{ | ||
// [databind#2973] | ||
static class WeirdTokenHandler | ||
extends DeserializationProblemHandler | ||
{ | ||
@Override | ||
public Object handleUnexpectedToken(DeserializationContext ctxt, | ||
JavaType targetType, JsonToken t, JsonParser p, | ||
String failureMsg) | ||
throws IOException | ||
{ | ||
String result = p.currentToken().toString(); | ||
p.skipChildren(); | ||
return result; | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
// [databind#2973] | ||
public void testUnexpectedToken2973() throws Exception | ||
{ | ||
// First: without handler, should get certain failure | ||
ObjectMapper mapper = sharedMapper(); | ||
try { | ||
mapper.readValue("{ }", String.class); | ||
fail("Should not pass"); | ||
} catch (MismatchedInputException e) { | ||
verifyException(e, "Cannot deserialize value of type `java.lang.String` from Object value"); | ||
} | ||
|
||
// But DeserializationProblemHandler should resolve: | ||
mapper = jsonMapperBuilder() | ||
.addHandler(new WeirdTokenHandler()) | ||
.build(); | ||
; | ||
String str = mapper.readValue("{ }", String.class); | ||
assertEquals("START_OBJECT", str); | ||
} | ||
} |