Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 25, 2025
2 parents d7b2b6d + 79b2de3 commit 19bcc0b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Project: jackson-databind
#4867: Add `Optional<JsonNode> JsonNode.asOptional()` convenience method
(fix by Joo-Hyuk K)
#4869: Add `JsonNode.values()` to replace `elements()`
#4896: Coercion shouldn't be necessary for Enums specifying an empty string
(reported by @joaocanaverde-blue)
2.18.3 (not yet released)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public boolean isAnnotationBundle(Annotation ann) {
/**********************************************************************
*/

@Override // since 2.16
@Override
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[] names)
{
Expand All @@ -176,7 +176,9 @@ public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedC
JsonProperty property = field.getAnnotation(JsonProperty.class);
if (property != null) {
String propValue = property.value();
if (propValue != null && !propValue.isEmpty()) {
if (propValue != null) {
// 24-Jan-2025, tatu: [databind#4896] Should not skip "" with enums
// && !propValue.isEmpty()) {
enumToPropertyMap.put(field.getName(), propValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ private final static int findSize(int size)
return result;
}

public Object find(String key) {
public Object find(String key)
{
int slot = key.hashCode() & _hashMask;
int ix = (slot<<1);
Object match = _hashArea[ix];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public Object deserializeKey(String key, DeserializationContext ctxt) {
}
}


@JsonDeserialize(using = AnEnumDeserializer.class, keyUsing = AnEnumKeyDeserializer.class)
public enum LanguageCodeMixin {
}
Expand Down Expand Up @@ -270,6 +269,18 @@ public static Operation3006 forValue(final String idStr) {
}
}

// [databind#4896]
enum YesOrNoOrEmpty4896 {
@JsonProperty("")
EMPTY,

@JsonProperty("yes")
YES,

@JsonProperty("no")
NO;
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -816,4 +827,16 @@ public void testEnumFeature_READ_ENUM_KEYS_USING_INDEX_isDisabledByDefault() {
assertFalse(READER.without(EnumFeature.READ_ENUM_KEYS_USING_INDEX)
.isEnabled(EnumFeature.READ_ENUM_KEYS_USING_INDEX));
}

// [databind#4896]
@Test
public void testEnumReadFromEmptyString() throws Exception {
// First, regular value
assertEquals(YesOrNoOrEmpty4896.YES,
MAPPER.readerFor(YesOrNoOrEmpty4896.class)
.readValue(q("yes")));
assertEquals(YesOrNoOrEmpty4896.EMPTY,
MAPPER.readerFor(YesOrNoOrEmpty4896.class)
.readValue(q("")));
}
}

0 comments on commit 19bcc0b

Please sign in to comment.