diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-02-27 19:52:22 -0800 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2020-02-27 19:52:22 -0800 |
commit | 771f6c6b939b78923a3df95c39b5593f8ba2ad09 (patch) | |
tree | 0ead58a52202029431bf6461ebfdfd17c179d341 /src/test/java/com/fasterxml/jackson/databind/jsontype | |
parent | cb922358a72b13867291a972c14bc8c5530140cf (diff) | |
download | jackson-databind-771f6c6b939b78923a3df95c39b5593f8ba2ad09.tar.gz |
First improvement wrt #2632: change to give more meaningful fail message.
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 "); + } + } } |