-
-
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
170a414
commit 09e5ba1
Showing
6 changed files
with
164 additions
and
9 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
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
94 changes: 94 additions & 0 deletions
94
...test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicWithDefaultImpl1565.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,94 @@ | ||
package com.fasterxml.jackson.databind.jsontype; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class TestPolymorphicWithDefaultImpl1565 extends BaseMapTest | ||
{ | ||
// [databind#1565] | ||
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, | ||
property="typeInfo", defaultImpl = CBaseClass1565.class) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(CDerived1565.class) | ||
}) | ||
public static interface CTestInterface1565 | ||
{ | ||
public String getName(); | ||
public void setName(String name); | ||
public String getTypeInfo(); | ||
} | ||
|
||
static class CBaseClass1565 implements CTestInterface1565 | ||
{ | ||
private String mName; | ||
|
||
@Override | ||
public String getName() { | ||
return(mName); | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
mName = name; | ||
} | ||
|
||
@Override | ||
public String getTypeInfo() { | ||
return "base"; | ||
} | ||
} | ||
|
||
@JsonTypeName("derived") | ||
static class CDerived1565 extends CBaseClass1565 | ||
{ | ||
public String description; | ||
|
||
@Override | ||
public String getTypeInfo() { | ||
return "derived"; | ||
} | ||
} | ||
|
||
// [databind#1861] | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = DefaultImpl1861.class) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(name = "a", value = Impl1861A.class) | ||
}) | ||
static abstract class Bean1861 { | ||
public String base; | ||
} | ||
|
||
static class DefaultImpl1861 extends Bean1861 { | ||
public int id; | ||
} | ||
|
||
static class Impl1861A extends Bean1861 { | ||
public int valueA; | ||
} | ||
|
||
/* | ||
/********************************************************************** | ||
/* Test methods | ||
/********************************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
// [databind#1565] | ||
public void testIncompatibleDefaultImpl1565() throws Exception | ||
{ | ||
String value = "{\"typeInfo\": \"derived\", \"name\": \"John\", \"description\": \"Owner\"}"; | ||
CDerived1565 result = MAPPER.readValue(value, CDerived1565.class); | ||
assertNotNull(result); | ||
} | ||
|
||
// [databind#1861] | ||
public void testWithIncompatibleTargetType1861() throws Exception | ||
{ | ||
// Should allow deserialization even if `defaultImpl` incompatible | ||
Impl1861A result = MAPPER.readValue(aposToQuotes("{'type':'a','base':'foo','valueA':3}"), | ||
Impl1861A.class); | ||
assertNotNull(result); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/com/fasterxml/jackson/failing/SubTypeResolution1964Test.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,43 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
@SuppressWarnings("serial") | ||
public class SubTypeResolution1964Test extends BaseMapTest | ||
{ | ||
static class AccessModel { | ||
private Map<Object, Collection<String>> repositoryPrivileges; | ||
|
||
public AccessModel() { | ||
repositoryPrivileges = new HashMap<>(); | ||
} | ||
|
||
public Map<Object, Collection<String>> getRepositoryPrivileges() { | ||
return repositoryPrivileges; | ||
} | ||
|
||
public void setRepositoryPrivileges(Map<Object, Collection<String>> repositoryPrivileges) { | ||
this.repositoryPrivileges = repositoryPrivileges; | ||
} | ||
} | ||
|
||
static class CustomMap<T> extends LinkedHashMap<Object, T> { } | ||
|
||
public void testTypeCompatibility1964() throws Exception | ||
{ | ||
Map<Object, Collection<String>> repoPrivilegesMap = new CustomMap<>(); | ||
String key = "/storages/storage0/releases"; | ||
Collection<String> values = new HashSet<>(); | ||
values.add("ARTIFACTS_RESOLVE"); | ||
repoPrivilegesMap.put(key, values); | ||
|
||
AccessModel accessModel = new AccessModel(); | ||
accessModel.setRepositoryPrivileges(repoPrivilegesMap); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
String jsonStr = mapper.writeValueAsString(accessModel); | ||
assertNotNull(jsonStr); | ||
} | ||
} |