Skip to content
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

Global enum naming strategy to use when it's not set directly on a class level #4716

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

badoken
Copy link

@badoken badoken commented Sep 25, 2024

Closes #4674

CacheProvider cacheProvider, JsonNodeFactory nodeFactory,
ConstructorDetector ctorDetector)
public BaseSettings(AnnotationIntrospector ai, PropertyNamingStrategy pns,
EnumNamingStrategy ens, AccessorNamingStrategy.Provider accNaming,
Copy link
Member

Choose a reason for hiding this comment

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

Please don't make source incompatible changes. Add a new constructor and deprecate the old one.

*
* @param s Strategy instance to use
*
* @return Builder instance itself to allow chaining
Copy link
Member

Choose a reason for hiding this comment

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

add @since 2.18 to all new public methods (including the ones that you didn't add javadoc to)

* @throws IllegalArgumentException if {@code namingDef} is not an instance of {@link java.lang.Class} or
* not a subclass of {@link EnumNamingStrategy}.
*/
public static EnumNamingStrategy createEnumNamingStrategyInstance(Object namingDef, boolean canOverrideAccessModifiers) {
public static EnumNamingStrategy createEnumNamingStrategyInstance(Object namingDef, boolean canOverrideAccessModifiers, EnumNamingStrategy defaultNamingStrategy) {
Copy link
Member

Choose a reason for hiding this comment

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

add back the old method - this is an incompatible change to the API

@cowtowncoder cowtowncoder added the 2.19 Issues planned at 2.19 or later label Sep 25, 2024
@cowtowncoder
Copy link
Member

Makes sense overall (although +1 for concerns @pjfanning pointed out; cannot just change signatures of methods that may be in use).
Will not make it in 2.18 since we are about to release 2.18.0 but can go in 2.19 as soon as we start the branch.

@Test
void testUseEnumMappingStrategySetInMapper() {
ObjectMapper mapper = jsonMapperBuilder()
.enumNamingStrategy(EnumNamingStrategies.CamelCaseStrategy.INSTANCE)
Copy link
Member

@JooHyukKim JooHyukKim Sep 26, 2024

Choose a reason for hiding this comment

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

This seems awkward.
How about .enumNamingStrategy(EnumNamingStrategies.CamelCaseStrategy.class) then handle the instance internally?

Copy link
Member

Choose a reason for hiding this comment

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

No, I think strategy passed should be instance, not class. This is used for most configuration; mapper/builder not having to dynamically construct instances.
If we want instantiation, should instead pass factory; Class only to be used in cases where we must (from Annotation where you cannot indicate instance but only Class).

Copy link
Member

Choose a reason for hiding this comment

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

We could just ask for new EnumNamingStrategies.CamelCaseStrategy(), but if there's already INSTANCE can use that.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, makes sense👍🏼

@badoken
Copy link
Author

badoken commented Sep 26, 2024

Hey @pjfanning, @cowtowncoder, thanks for the review
Following your advice added @since 2.19 and kept the original signature methods, please let me know if now it looks good

@cowtowncoder
Copy link
Member

Needs to be-based against 2.19 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.19 Issues planned at 2.19 or later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants