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

Use static PropertyNamingStrategy instances in POJOPropertiesCollector._findNamingStrategy() #4109

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,50 @@ private PropertyNamingStrategy _findNamingStrategy()
return pns;
}
}

Copy link
Member

@JooHyukKim JooHyukKim Sep 11, 2023

Choose a reason for hiding this comment

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

// Plz check Line 1448
PropertyNamingStrategy pns = hi.namingStrategyInstance(_config, _classDef, namingClass);

Possibly, at line 1448 (above) HandlerInstantiator is also doing what we are trying to prevent to happen here. namingStrategyInstance() JavaDoc says....

/**
  * Method called to construct a NamingStrategy instance used for specified
  * class.
  *
  * @since 2.1
  */

Copy link
Contributor Author

@takezoe takezoe Oct 7, 2023

Choose a reason for hiding this comment

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

HandlerInstantiator is given through configuration and it can return any instance of PropertyNamingStrategy. I think we can't rescue if HandlerInstantiator is used.

// PropertyNamingStrategy
if (namingClass == PropertyNamingStrategy.SnakeCaseStrategy.class) {
Copy link
Member

Choose a reason for hiding this comment

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

can this list of if stmts be made into a switch stmt with cases instead?

Copy link
Member

Choose a reason for hiding this comment

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

As far as I know the baseline version Java 8 doesn't support switch for Class 🧐

Copy link
Member

Choose a reason for hiding this comment

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

If we were to do this, I think switch logic should be moved into a static method of PropertyNamingStrategies, so here we would just call that method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved switching logic to PropertyNamingStrategies and added a test case.

return PropertyNamingStrategies.SNAKE_CASE;
}
if (namingClass == PropertyNamingStrategy.UpperCamelCaseStrategy.class) {
return PropertyNamingStrategies.UPPER_CAMEL_CASE;
}
if (namingClass == PropertyNamingStrategy.KebabCaseStrategy.class) {
return PropertyNamingStrategies.KEBAB_CASE;
}
if (namingClass == PropertyNamingStrategy.LowerDotCaseStrategy.class) {
return PropertyNamingStrategies.LOWER_DOT_CASE;
}
if (namingClass == PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class) {
return PropertyNamingStrategies.SNAKE_CASE;
}
if (namingClass == PropertyNamingStrategy.PascalCaseStrategy.class) {
return PropertyNamingStrategies.UPPER_CAMEL_CASE;
}

// PropertyNamingStrategies
if (namingClass == PropertyNamingStrategies.SnakeCaseStrategy.class) {
return PropertyNamingStrategies.SNAKE_CASE;
}
if (namingClass == PropertyNamingStrategies.UpperSnakeCaseStrategy.class) {
return PropertyNamingStrategies.UPPER_SNAKE_CASE;
}
if (namingClass == PropertyNamingStrategies.LowerCamelCaseStrategy.class) {
return PropertyNamingStrategies.LOWER_CAMEL_CASE;
}
if (namingClass == PropertyNamingStrategies.UpperCamelCaseStrategy.class) {
return PropertyNamingStrategies.UPPER_CAMEL_CASE;
}
if (namingClass == PropertyNamingStrategies.LowerCaseStrategy.class) {
return PropertyNamingStrategies.LOWER_CASE;
}
if (namingClass == PropertyNamingStrategies.KebabCaseStrategy.class) {
return PropertyNamingStrategies.KEBAB_CASE;
}
if (namingClass == PropertyNamingStrategies.LowerDotCaseStrategy.class) {
return PropertyNamingStrategies.LOWER_DOT_CASE;
}

return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass,
_config.canOverrideAccessModifiers());
}
Expand Down