Skip to content

Commit 19bcc0b

Browse files
committed
Merge branch '2.19'
2 parents d7b2b6d + 79b2de3 commit 19bcc0b

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project: jackson-databind
4141
#4867: Add `Optional<JsonNode> JsonNode.asOptional()` convenience method
4242
(fix by Joo-Hyuk K)
4343
#4869: Add `JsonNode.values()` to replace `elements()`
44+
#4896: Coercion shouldn't be necessary for Enums specifying an empty string
45+
(reported by @joaocanaverde-blue)
4446
4547
2.18.3 (not yet released)
4648

src/main/java/tools/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public boolean isAnnotationBundle(Annotation ann) {
167167
/**********************************************************************
168168
*/
169169

170-
@Override // since 2.16
170+
@Override
171171
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
172172
Enum<?>[] enumValues, String[] names)
173173
{
@@ -176,7 +176,9 @@ public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedC
176176
JsonProperty property = field.getAnnotation(JsonProperty.class);
177177
if (property != null) {
178178
String propValue = property.value();
179-
if (propValue != null && !propValue.isEmpty()) {
179+
if (propValue != null) {
180+
// 24-Jan-2025, tatu: [databind#4896] Should not skip "" with enums
181+
// && !propValue.isEmpty()) {
180182
enumToPropertyMap.put(field.getName(), propValue);
181183
}
182184
}

src/main/java/tools/jackson/databind/util/CompactStringObjectMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ private final static int findSize(int size)
9494
return result;
9595
}
9696

97-
public Object find(String key) {
97+
public Object find(String key)
98+
{
9899
int slot = key.hashCode() & _hashMask;
99100
int ix = (slot<<1);
100101
Object match = _hashArea[ix];

src/test/java/tools/jackson/databind/deser/enums/EnumDeserializationTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public Object deserializeKey(String key, DeserializationContext ctxt) {
202202
}
203203
}
204204

205-
206205
@JsonDeserialize(using = AnEnumDeserializer.class, keyUsing = AnEnumKeyDeserializer.class)
207206
public enum LanguageCodeMixin {
208207
}
@@ -270,6 +269,18 @@ public static Operation3006 forValue(final String idStr) {
270269
}
271270
}
272271

272+
// [databind#4896]
273+
enum YesOrNoOrEmpty4896 {
274+
@JsonProperty("")
275+
EMPTY,
276+
277+
@JsonProperty("yes")
278+
YES,
279+
280+
@JsonProperty("no")
281+
NO;
282+
}
283+
273284
/*
274285
/**********************************************************
275286
/* Test methods
@@ -816,4 +827,16 @@ public void testEnumFeature_READ_ENUM_KEYS_USING_INDEX_isDisabledByDefault() {
816827
assertFalse(READER.without(EnumFeature.READ_ENUM_KEYS_USING_INDEX)
817828
.isEnabled(EnumFeature.READ_ENUM_KEYS_USING_INDEX));
818829
}
830+
831+
// [databind#4896]
832+
@Test
833+
public void testEnumReadFromEmptyString() throws Exception {
834+
// First, regular value
835+
assertEquals(YesOrNoOrEmpty4896.YES,
836+
MAPPER.readerFor(YesOrNoOrEmpty4896.class)
837+
.readValue(q("yes")));
838+
assertEquals(YesOrNoOrEmpty4896.EMPTY,
839+
MAPPER.readerFor(YesOrNoOrEmpty4896.class)
840+
.readValue(q("")));
841+
}
819842
}

0 commit comments

Comments
 (0)