From af21e312bb5586aaf6a2b61ca6b809895bf08e27 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 12 Feb 2020 14:57:21 -0800 Subject: [PATCH] Add a failing test for #2605 --- .../failing/EnumPolymorphic2605Test.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/failing/EnumPolymorphic2605Test.java diff --git a/src/test/java/com/fasterxml/jackson/failing/EnumPolymorphic2605Test.java b/src/test/java/com/fasterxml/jackson/failing/EnumPolymorphic2605Test.java new file mode 100644 index 0000000000..ad3b2e8e8f --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/failing/EnumPolymorphic2605Test.java @@ -0,0 +1,45 @@ +package com.fasterxml.jackson.failing; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import com.fasterxml.jackson.databind.*; + +public class EnumPolymorphic2605Test extends BaseMapTest +{ + // for [databind#2605] + static class EnumContaintingClass > { + @JsonTypeInfo( + use = JsonTypeInfo.Id.CLASS, + include = JsonTypeInfo.As.PROPERTY, + property = "@class" + ) + private ENUM_TYPE selected; + + protected EnumContaintingClass() { } + + public EnumContaintingClass(ENUM_TYPE selected) { + this.selected = selected; + } + + public ENUM_TYPE getSelected() { + return selected; + } + + public void setSelected(ENUM_TYPE selected) { + this.selected = selected; + } + } + + static enum TestEnum { FIRST, SECOND, THIRD; } + + private final ObjectMapper MAPPER = newJsonMapper(); + + // for [databind#2605] + public void testRoundtrip() throws Exception + { + EnumContaintingClass gui = new EnumContaintingClass(TestEnum.SECOND); + String str = MAPPER.writeValueAsString(gui); + Object o = MAPPER.readerFor(EnumContaintingClass.class).readValue(str); + assertNotNull(o); + } +}