Skip to content

Commit 77e8b62

Browse files
committed
Merge branch '2.12' into 2.13
2 parents faa2484 + 70ba54f commit 77e8b62

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Project: jackson-databind
8383
(contributed by Abishek R)
8484
#3271: String property deserializes null as "null" for JsonTypeInfo.As.EXISTING_PROPERTY
8585
(reported by jonc2@github)
86+
#3280: Can not deserialize json to enum value with Object-/Array-valued input,
87+
`@JsonCreator`
88+
(reported by peteryuanpan@github)
8689
- Fix to avoid problem with `BigDecimalNode`, scale of `Integer.MIN_VALUE` (see
8790
[dataformats-binary#264] for details)
8891
- Extend handling of `FAIL_ON_NULL_FOR_PRIMITIVES` to cover coercion from (Empty) String

src/main/java/com/fasterxml/jackson/databind/deser/std/FactoryBasedEnumDeserializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ protected Object deserializeEnumUsingPropertyBased(final JsonParser p, final Des
197197
continue;
198198
}
199199
// 26-Nov-2020, tatu: ... what should we do here tho?
200+
p.skipChildren();
200201
}
201202
return creator.build(ctxt, buffer);
202203
}

src/test/java/com/fasterxml/jackson/databind/deser/creators/EnumCreatorTest.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.fasterxml.jackson.databind.deser.creators;
22

33
import java.math.BigDecimal;
4-
import java.util.*;
4+
import java.util.Collection;
5+
import java.util.EnumMap;
6+
import java.util.EnumSet;
7+
import java.util.HashMap;
8+
import java.util.List;
59

610
import com.fasterxml.jackson.annotation.JsonCreator;
711
import com.fasterxml.jackson.annotation.JsonGetter;
@@ -187,13 +191,33 @@ public String toString() {
187191
}
188192
}
189193

194+
// [databind#3280]
195+
static enum Enum3280 {
196+
x("x"),
197+
y("y"),
198+
z("z");
199+
private final String value;
200+
Enum3280(String value) {
201+
this.value = value;
202+
}
203+
@JsonCreator
204+
public static Enum3280 getByValue(@JsonProperty("b") String value) {
205+
for (Enum3280 e : Enum3280.values()) {
206+
if (e.value.equals(value)) {
207+
return e;
208+
}
209+
}
210+
return null;
211+
}
212+
}
213+
190214
/*
191215
/**********************************************************
192216
/* Test methods
193217
/**********************************************************
194218
*/
195219

196-
protected final ObjectMapper MAPPER = new ObjectMapper();
220+
protected final ObjectMapper MAPPER = newJsonMapper();
197221

198222
public void testCreatorEnums() throws Exception {
199223
EnumWithCreator value = MAPPER.readValue("\"enumA\"", EnumWithCreator.class);
@@ -309,4 +333,15 @@ public void testMultiArgEnumInCollections() throws Exception
309333
assertEquals(Enum929.B, valueList.get(2));
310334
}
311335

336+
// for [databind#3280]
337+
public void testPropertyCreatorEnum3280() throws Exception
338+
{
339+
final ObjectReader r = MAPPER.readerFor(Enum3280.class);
340+
assertEquals(Enum3280.x, r.readValue("{\"b\":\"x\"}"));
341+
assertEquals(Enum3280.x, r.readValue("{\"a\":\"1\", \"b\":\"x\"}"));
342+
assertEquals(Enum3280.y, r.readValue("{\"b\":\"y\", \"a\":{}}"));
343+
assertEquals(Enum3280.y, r.readValue("{\"b\":\"y\", \"a\":{}}"));
344+
assertEquals(Enum3280.x, r.readValue("{\"a\":[], \"b\":\"x\"}"));
345+
assertEquals(Enum3280.x, r.readValue("{\"a\":{}, \"b\":\"x\"}"));
346+
}
312347
}

0 commit comments

Comments
 (0)