diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-02-27 19:53:04 -0800 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-02-27 19:53:04 -0800 |
commit | 83d1835728959236ccfe17450035f84c44da184d (patch) | |
tree | c7527ef83f51d3111f61c1f77810fea3a5eb268e /src/test/java/com/fasterxml/jackson/databind/jsontype | |
parent | d354028fd658b95448f5f15e2e263515878be14a (diff) | |
parent | 771f6c6b939b78923a3df95c39b5593f8ba2ad09 (diff) | |
download | jackson-databind-83d1835728959236ccfe17450035f84c44da184d.tar.gz |
Merge branch '2.10' into 2.11
Diffstat (limited to 'src/test/java/com/fasterxml/jackson/databind/jsontype')
-rw-r--r-- | src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolutionTest.java (renamed from src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java) | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolutionTest.java index fa9ef01e7..1b29a77bb 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolutionTest.java @@ -3,10 +3,13 @@ package com.fasterxml.jackson.databind.jsontype; import java.util.*; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + import com.fasterxml.jackson.databind.*; /** - * Test for [databind#1964], wherein slightly incompatible type hierarchy, + * Originally test for [databind#1964], wherein slightly incompatible type hierarchy, * where `Map` key is downcast from `String` to `Object` (via use of "raw" * types to force compiler to ignore incompatibility) causes exception * during serialization. Although ideally code would not force round peg @@ -14,7 +17,7 @@ import com.fasterxml.jackson.databind.*; * such downcast just for Map key types (for now at least). */ @SuppressWarnings("serial") -public class SubTypeResolution1964Test extends BaseMapTest +public class SubTypeResolutionTest extends BaseMapTest { // [databind#1964] static class AccessModel { @@ -65,7 +68,26 @@ public class SubTypeResolution1964Test extends BaseMapTest static class MetaAttribute<M, V, B> extends AbstractMetaValue<M, V, B> { public MetaAttribute() { } } - + + // [databind#2632]: fail to specialize type-erased + @SuppressWarnings("rawtypes") + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) + @JsonSubTypes(value = { + @JsonSubTypes.Type(value = Either.Left.class, name = "left"), + @JsonSubTypes.Type(value = Either.Right.class, name = "right") + }) + static class Either<L, R> { + static class Left<T> extends Either { } + static class Right<T> extends Either { } + } + + static class Foo { + @SuppressWarnings("unchecked") + public Either<String, String> getEither() { + return new Either.Right<String>(); + } + } + /* /********************************************************************** /* Unit tests @@ -103,4 +125,21 @@ public class SubTypeResolution1964Test extends BaseMapTest // ... could/should verify more, perhaps, but for now let it be. assertNotNull(jsonStr); } + + // [databind#2632]: fail to specialize type-erased + public void testSpecializeIncompatibleRawType() throws Exception + { + // 27-Feb-2020, tatu: First things first; incompatible typing should + // cause reasonable exception + // ... although since it's writing, perhaps should NOT fail at all? + String json; + + try { + json = MAPPER.writeValueAsString(new Foo()); + assertNotNull(json); + fail("Should not (yet?) pass"); + } catch (JsonMappingException e) { + verifyException(e, "Failed to specialize base type "); + } + } } |