diff --git a/src/test/java/tools/jackson/databind/deser/creators/EnumCreator4544Test.java b/src/test/java/tools/jackson/databind/deser/creators/EnumCreator4544Test.java deleted file mode 100644 index 0b5385a523..0000000000 --- a/src/test/java/tools/jackson/databind/deser/creators/EnumCreator4544Test.java +++ /dev/null @@ -1,57 +0,0 @@ -package tools.jackson.databind.deser.creators; - -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import tools.jackson.databind.ObjectMapper; -import tools.jackson.databind.testutil.DatabindTestUtil; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class EnumCreator4544Test extends DatabindTestUtil -{ - static class DataClass4544 { - public DataEnum4544 data; - } - - public enum DataEnum4544 - { - TEST(0); - - private final int data; - - DataEnum4544(int data) { - this.data = data; - } - - // Important! Without ignoring accessor will find logical property - // that matches Creator parameter... and assume properties-based - @JsonIgnore - public int getData() { - return data; - } - - @JsonCreator - public static DataEnum4544 of(@ImplicitName("data") int data) { - return Arrays.stream(values()) - .filter(it -> it.getData() == data) - .findAny().get(); - } - } - - @Test - void test4544() throws Exception { - final ObjectMapper mapper = jsonMapperBuilder() - .annotationIntrospector(new ImplicitNameIntrospector()) - .build(); - - String json = a2q("{'data': 0}"); - DataClass4544 data = mapper.readValue(json, DataClass4544.class); - - assertEquals(DataEnum4544.TEST, data.data); - } -} diff --git a/src/test/java/tools/jackson/databind/deser/creators/EnumCreatorTest.java b/src/test/java/tools/jackson/databind/deser/creators/EnumCreatorTest.java index 2fd56e479a..8e35869825 100644 --- a/src/test/java/tools/jackson/databind/deser/creators/EnumCreatorTest.java +++ b/src/test/java/tools/jackson/databind/deser/creators/EnumCreatorTest.java @@ -7,21 +7,22 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import tools.jackson.core.type.TypeReference; + import tools.jackson.databind.*; import tools.jackson.databind.deser.Deserializers; import tools.jackson.databind.deser.jdk.EnumDeserializer; import tools.jackson.databind.exc.ValueInstantiationException; import tools.jackson.databind.introspect.AnnotatedMethod; import tools.jackson.databind.module.SimpleModule; +import tools.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.*; -import static tools.jackson.databind.testutil.DatabindTestUtil.*; - -public class EnumCreatorTest +public class EnumCreatorTest extends DatabindTestUtil { protected enum EnumWithCreator { A, B; @@ -227,6 +228,35 @@ public static Enum3280 getByValue(@JsonProperty("b") String value) { } } + static class DataClass4544 { + public DataEnum4544 data; + } + + public enum DataEnum4544 + { + TEST(0); + + private final int data; + + DataEnum4544(int data) { + this.data = data; + } + + // Important! Without ignoring accessor will find logical property + // that matches Creator parameter... and assume properties-based + @JsonIgnore + public int getData() { + return data; + } + + @JsonCreator + public static DataEnum4544 of(@ImplicitName("data") int data) { + return Arrays.stream(values()) + .filter(it -> it.getData() == data) + .findAny().get(); + } + } + /* /********************************************************** /* Test methods @@ -403,4 +433,17 @@ public void testEnumsFromStringUnwrapped() throws Exception assertEquals(TestEnumFromString.class, ob.getClass()); assertSame(TestEnumFromString.ENUM_A, ob); } + + // for [databind#4544] + @Test + void testEnumsWithImplicitNames4544() throws Exception { + final ObjectMapper mapper = jsonMapperBuilder() + .annotationIntrospector(new ImplicitNameIntrospector()) + .build(); + + String json = a2q("{'data': 0}"); + DataClass4544 data = mapper.readValue(json, DataClass4544.class); + + assertEquals(DataEnum4544.TEST, data.data); + } }