Skip to content

Add enum features into JsonFormat.Feature #3731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 20, 2023

Conversation

Siwach16
Copy link
Contributor

Add enum features into JsonFormat.Feature

  • READ_UNKNOWN_ENUM_VALUES_AS_NULL
  • READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE

Related PR: FasterXML/jackson-annotations#211

Issue : #3637

@@ -1712,7 +1712,10 @@ public JsonDeserializer<?> createEnumDeserializer(DeserializationContext ctxt,
if (deser == null) {
deser = new EnumDeserializer(constructEnumResolver(enumClass,
config, beanDesc.findJsonValueAccessor()),
config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS));
config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS),
ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmh. This is problematic since DeserializationFeatures are meant to be per-call basis; that is, its value may be changed via ObjectReader so we cannot assume that value at this point will not change.
This is different from MapperFeatures which are per-mapper and cannot be changed.

Put another way, DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE needs to be accessed dynamically when needed, not on constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into the PR.
I have removed the features from constructor in BasicDeserializerFactory.

@cowtowncoder
Copy link
Member

Sounds good. There's some work needed but in general I like the addition.

One practical thing: before merging I need CLA:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

(unless you have sent one in the past -- it only needs to be done once,ever)

The usual way is to print the doc, fill & sign, scan/photo, email to info at fasterxml dot com.

Looking forward to getting these PRs merged, included in 2.15!

@Siwach16
Copy link
Contributor Author

Sounds good. There's some work needed but in general I like the addition.

One practical thing: before merging I need CLA:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

(unless you have sent one in the past -- it only needs to be done once,ever)

The usual way is to print the doc, fill & sign, scan/photo, email to info at fasterxml dot com.

Looking forward to getting these PRs merged, included in 2.15!

Thanks @cowtowncoder , I have sent the Signed CLA document.

@Siwach16
Copy link
Contributor Author

@cowtowncoder Can you please guide me if something else needs to be done here? Thanks.

@@ -213,4 +224,38 @@ public void testEnumWithAliasAndDefaultForUnknownValueEnabled() throws Exception
MyEnum2352_3 multipleAliases2 = reader.readValue(q("multipleAliases2"));
assertEquals(MyEnum2352_3.C, multipleAliases2);
}

public void testEnumWithDefaultForUnknownValueEnabled() throws JsonProcessingException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just use throws Exception here since JsonProcessingException is renamed in 3.0 (master).

@cowtowncoder
Copy link
Member

@Siwach16 I hope to get all of this reviewed soon; will add some notes but I think it looks good overall.

verifyException(e, "[JACKSON, OK, RULES]");
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to testing single Enum property it'd be good to see if things work for EnumSets?

I don't remember if things might just work due to delegation, but it might be necessary to change EnumSetDeserializer. Adding a test would clarify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test cases for EnumSet. Please have look if behaviour is expected.Thanks.

@cowtowncoder
Copy link
Member

Planning to get this merged today.

@@ -77,14 +81,16 @@ public EnumDeserializer(EnumResolver byNameResolver, Boolean caseInsensitive)
/**
* @since 2.9
*/
protected EnumDeserializer(EnumDeserializer base, Boolean caseInsensitive)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to leave old constructor for backwards-compatibility; I can add it after merging.

@cowtowncoder cowtowncoder merged commit 678f31c into FasterXML:2.15 Jan 20, 2023
@cowtowncoder cowtowncoder added this to the 2.15.0 milestone Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants