Skip to content

Commit

Permalink
Minor clean up, add release notes for #3637
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 20, 2023
1 parent 678f31c commit 4113a82
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>
implements ContextualDeserializer
Expand Down Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -150,17 +160,28 @@ 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)) {
return this;
}
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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 4113a82

Please sign in to comment.