-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use static PropertyNamingStrategy instances in POJOPropertiesCollector._findNamingStrategy() #4109
Conversation
…r._findNamingStrategy()
@@ -1450,6 +1450,50 @@ private PropertyNamingStrategy _findNamingStrategy() | |||
return pns; | |||
} | |||
} | |||
|
There was a problem hiding this comment.
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
*/
There was a problem hiding this comment.
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.
@@ -1450,6 +1450,50 @@ private PropertyNamingStrategy _findNamingStrategy() | |||
return pns; | |||
} | |||
} | |||
|
|||
// PropertyNamingStrategy | |||
if (namingClass == PropertyNamingStrategy.SnakeCaseStrategy.class) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
🧐
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@takezoe First of all, thank you for offering this contribution! Now... I am not a big fan of this idea. I get that this could reduce memory usage slightly as well as tiny improvement in processing speed. But in most cases this occurs just once per class being (de)serialized. So let me ask you this: what is the motivation for suggesting the change? |
@cowtowncoder Sorry for late response. My motivation is eliminating risk of dead-lock caused by pre-defined strategies with In fact, we faced the dead-lock issue by mixed use of
Of course, we can fix our codes to only use |
✅ True, sounds like keeping consistency ❌ Considering this fix pertains to a class deprecated since Jackson |
Then, I hope that deprecated static fields of |
The challenge is that deprecation only occurred in 2.12, first released under 3 years ago (and latest patch bit over 1 year ago), so despite the risk, there's very likely code out there that would get broken when someone upgrades from 2.15 or earlier to 2.16, should we drop deprecated classes now. This compared risk of possible race condition due to someone using old implementations (I don't believe mixing of new and old should be issue but simply use of old ones). What I can do is file an issue for dropping these classes from Jackson 2.17, if agreed to by discussions within Jackson developer community. |
Thank you. That sounds good! |
Not sure if this pull request has a chance to be accepted but I anyway updated to cover this comment. |
I think I'd rather go with the alternate approach on warning, deprecation, eventual removal. |
Closing in favor of #4144 |
Returns static
PropertyNamingStrategy
instances defined inPropertyNamingStrategies
fromPOJOPropertiesCollector._findNamingStrategy()
instead of creating new instance every time.This also eliminates risk of dead-lock mentioned in #2715 when subclasses of
PropertyNamingStrategy
are used with@JsonNaiming
though they have been already deprecated.