From 4113a825fb64c8298acc0feb8f1e322fe8a2176f Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 19 Jan 2023 21:24:19 -0800 Subject: [PATCH] Minor clean up, add release notes for #3637 --- release-notes/CREDITS-2.x | 5 +++ release-notes/VERSION-2.x | 3 ++ .../databind/deser/std/EnumDeserializer.java | 39 +++++++++++++++---- .../databind/deser/enums/EnumAltIdTest.java | 2 +- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 37e2dcf3c7..56f686b670 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1554,3 +1554,8 @@ Sim Yih Tsern (yihtsern@github) (2.15.0) * Contributed fix for #3342: `JsonTypeInfo.As.EXTERNAL_PROPERTY` does not work with record wrappers (2.15.0) + +Ajay Siwach (Siwach16@github) + * Contributed #3637: Add enum features into `@JsonFormat.Feature` + (2.15.0) + diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 8cac1fe524..079bf70369 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,6 +16,9 @@ Project: jackson-databind (fix contributed by Sim Y-T) #3342: `JsonTypeInfo.As.EXTERNAL_PROPERTY` does not work with record wrappers (fix contributed by Sim Y-T) +#3637: Add enum features into `@JsonFormat.Feature` + (requested by @Anatoly4444) + (fix contributed by Ajay S) #3654: Infer `@JsonCreator(mode = Mode.DELEGATING)` from use of `@JsonValue`) #3676: Allow use of `@JsonCreator(mode = Mode.PROPERTIES)` creator for POJOs with"empty String" coercion diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java index 6f7852e4e2..879c933fca 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java @@ -25,7 +25,7 @@ * Deserializer class that can deserialize instances of * specified Enum class from Strings and Integers. */ -@JacksonStdImpl // was missing until 2.6 +@JacksonStdImpl public class EnumDeserializer extends StdScalarDeserializer implements ContextualDeserializer @@ -79,9 +79,10 @@ public EnumDeserializer(EnumResolver byNameResolver, Boolean caseInsensitive) } /** - * @since 2.9 + * @since 2.15 */ - protected EnumDeserializer(EnumDeserializer base, Boolean caseInsensitive, Boolean useDefaultValueForUnknownEnum, Boolean useNullForUnknownEnum) + protected EnumDeserializer(EnumDeserializer base, Boolean caseInsensitive, + Boolean useDefaultValueForUnknownEnum, Boolean useNullForUnknownEnum) { super(base); _lookupByName = base._lookupByName; @@ -93,6 +94,15 @@ protected EnumDeserializer(EnumDeserializer base, Boolean caseInsensitive, Boole _useNullForUnknownEnum = useNullForUnknownEnum; } + /** + * @since 2.9 + * @deprecated Since 2.15 + */ + @Deprecated + protected EnumDeserializer(EnumDeserializer base, Boolean caseInsensitive) { + this(base, caseInsensitive, null, null); + } + /** * @deprecated Since 2.9 */ @@ -150,9 +160,10 @@ public static JsonDeserializer deserializerForNoArgsCreator(DeserializationCo } /** - * @since 2.9 + * @since 2.15 */ - public EnumDeserializer withResolved(Boolean caseInsensitive, Boolean useDefaultValueForUnknownEnum, Boolean useNullForUnknownEnum) { + public EnumDeserializer withResolved(Boolean caseInsensitive, + Boolean useDefaultValueForUnknownEnum, Boolean useNullForUnknownEnum) { if (Objects.equals(_caseInsensitive, caseInsensitive) && Objects.equals(_useDefaultValueForUnknownEnum, useDefaultValueForUnknownEnum) && Objects.equals(_useNullForUnknownEnum, useNullForUnknownEnum)) { @@ -160,7 +171,17 @@ public EnumDeserializer withResolved(Boolean caseInsensitive, Boolean useDefault } return new EnumDeserializer(this, caseInsensitive, useDefaultValueForUnknownEnum, useNullForUnknownEnum); } - + + /** + * @since 2.9 + * @deprecated Since 2.15 + */ + @Deprecated + public EnumDeserializer withResolved(Boolean caseInsensitive) { + return withResolved(caseInsensitive, + _useDefaultValueForUnknownEnum, _useNullForUnknownEnum); + } + @Override // since 2.9 public JsonDeserializer createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException @@ -391,12 +412,14 @@ protected CompactStringObjectMap _getToStringLookup(DeserializationContext ctxt) return lookup; } - private boolean useNullForUnknownEnum(DeserializationContext ctxt) { + // @since 2.15 + protected boolean useNullForUnknownEnum(DeserializationContext ctxt) { return Boolean.TRUE.equals(_useNullForUnknownEnum) || ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL); } - private boolean useDefaultValueForUnknownEnum(DeserializationContext ctxt) { + // @since 2.15 + protected boolean useDefaultValueForUnknownEnum(DeserializationContext ctxt) { return (_enumDefaultValue != null) && (Boolean.TRUE.equals(_useDefaultValueForUnknownEnum) || ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumAltIdTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumAltIdTest.java index d75b70a666..a744b429dd 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumAltIdTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumAltIdTest.java @@ -1,12 +1,12 @@ package com.fasterxml.jackson.databind.deser.enums; -import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.util.EnumSet; import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; import com.fasterxml.jackson.annotation.JsonFormat; + import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.DeserializationFeature;