-
-
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
Warn about/disallow @JsonCreator on enum constructors? #1272
Comments
This is a valid concern, as there is no valid use case for But if feasible I think it would be a good idea in this particular case to signal an error. There's no real mechanism to warn about things in Jackson (logging is avoided on purpose), so this would mean an exception. Given that I plan on rewriting the whole creator introspection system for 2.9 (if possible) or later minor versions, I think this would naturally fit in with that work, unless there's a simple enough change to make that work with current code. |
Quick note: #929 is now actually supported, so at least multi-argument factory methods are ok. |
Since |
It's currently valid to add the
@JsonCreator
annotation to an enum constructor, but that doesn't "do" anything. This might confuse users (it did confuse me when I found an occurrence in our code):@JsonCreator
then that method will be called upon each deserialization, while by definition an enum's constructor is invoked only once for each enum value.@JsonCreator
s yield anIllegalArgumentException
(see also @JsonCreator not working on a factory with multiple arguments for a enum type #929), but@JsonCreator
-annotated enum constructors with multiple parameters don't.@JsonValue
-annotated method there may even be a mismatch between the number and types of arguments accepted by the constructor (this is the scenario I found in our code): it's unclear then what Jackson will do. (Until one realizes that the constructor's@JsonCreator
annotation is bogus. That took me a while to figure out and is the reason I'm filing this issue.)The text was updated successfully, but these errors were encountered: