|
6 | 6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
7 | 7 | import com.fasterxml.jackson.annotation.JsonGetter;
|
8 | 8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
| 9 | + |
9 | 10 | import com.fasterxml.jackson.core.type.TypeReference;
|
| 11 | + |
10 | 12 | import com.fasterxml.jackson.databind.*;
|
11 | 13 | import com.fasterxml.jackson.databind.deser.Deserializers;
|
12 | 14 | import com.fasterxml.jackson.databind.deser.std.EnumDeserializer;
|
@@ -140,6 +142,36 @@ static class MyEnum960Wrapper {
|
140 | 142 | public MyEnum960 value;
|
141 | 143 | }
|
142 | 144 |
|
| 145 | + static enum Enum1291 { |
| 146 | + |
| 147 | + V1("val1"), |
| 148 | + V2("val2"), |
| 149 | + V3("val3"), |
| 150 | + V4("val4"), |
| 151 | + V5("val5"), |
| 152 | + V6("val6"); |
| 153 | + |
| 154 | + private final String name; |
| 155 | + |
| 156 | + Enum1291(String name) { |
| 157 | + this.name = name; |
| 158 | + } |
| 159 | + |
| 160 | + public static Enum1291 fromString(String name) { |
| 161 | + for (Enum1291 type : Enum1291.values()) { |
| 162 | + if (type.name.equals(name)) { |
| 163 | + return type; |
| 164 | + } |
| 165 | + } |
| 166 | + return Enum1291.valueOf(name.toUpperCase()); |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public String toString() { |
| 171 | + return name; |
| 172 | + } |
| 173 | + } |
| 174 | + |
143 | 175 | /*
|
144 | 176 | /**********************************************************
|
145 | 177 | /* Test methods
|
@@ -231,4 +263,13 @@ public void testNoArgEnumCreator() throws Exception
|
231 | 263 | MyEnum960 v = MAPPER.readValue("{\"value\":\"bogus\"}", MyEnum960.class);
|
232 | 264 | assertEquals(MyEnum960.VALUE, v);
|
233 | 265 | }
|
| 266 | + |
| 267 | + // for [databind#1291] |
| 268 | + public void testEnumCreators1291() throws Exception |
| 269 | + { |
| 270 | + ObjectMapper mapper = new ObjectMapper(); |
| 271 | + String json = mapper.writeValueAsString(Enum1291.V2); |
| 272 | + Enum1291 result = mapper.readValue(json, Enum1291.class); |
| 273 | + assertSame(Enum1291.V2, result); |
| 274 | + } |
234 | 275 | }
|
0 commit comments