-
-
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
ce7d1c9
commit f2c445d
Showing
3 changed files
with
77 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
64 changes: 64 additions & 0 deletions
64
src/test/java/com/fasterxml/jackson/databind/jsontype/GenericTypeId1735Test.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,64 @@ | ||
package com.fasterxml.jackson.databind.jsontype; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
// for [databind#1735]: | ||
public class GenericTypeId1735Test extends BaseMapTest | ||
{ | ||
static class Wrapper1735 { | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "type") | ||
public Payload1735 w; | ||
} | ||
|
||
static class Payload1735 { | ||
public void setValue(String str) { } | ||
} | ||
|
||
static class Nefarious1735 { | ||
public Nefarious1735() { | ||
throw new Error("Never call this constructor"); | ||
} | ||
|
||
public void setValue(String str) { | ||
throw new Error("Never call this setter"); | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = objectMapper(); | ||
|
||
private final static String NEF_CLASS = Nefarious1735.class.getName(); | ||
|
||
// Existing checks should kick in fine | ||
public void testSimpleTypeCheck1735() throws Exception | ||
{ | ||
try { | ||
MAPPER.readValue(aposToQuotes( | ||
"{'w':{'type':'"+NEF_CLASS+"'}}"), | ||
Wrapper1735.class); | ||
fail("Should not pass"); | ||
} catch (JsonMappingException e) { | ||
verifyException(e, "not subtype of"); | ||
} | ||
} | ||
|
||
// but this was not being verified early enough | ||
public void testNestedTypeCheck1735() throws Exception | ||
{ | ||
try { | ||
MAPPER.readValue(aposToQuotes( | ||
"{'w':{'type':'java.util.HashMap<java.lang.String,java.lang.String>'}}"), | ||
Wrapper1735.class); | ||
fail("Should not pass"); | ||
} catch (JsonMappingException e) { | ||
verifyException(e, "not subtype of"); | ||
} | ||
} | ||
} |