What's the correct way to instantiate ParameterNamesModule for constructor deserialization?

13 views
Skip to first unread message

Jean Dannemann

unread,
Jul 22, 2019, 11:04:44 AM7/22/19
to jackson-user

Whats the correct way to instantiate ParameterNamesModule for "constructor with all fields" deserialization?


It already works for me.. but it works in both ways!.. whats the difference of


new ParameterNamesModule()

and

ParameterNamesModule(JsonCreator.Mode.PROPERTIES)


Aso, I do NOT need to add the -parameters compiler argument for it to work


Maybe because I do not have a default noargs constructor declared


thanks in advance

Tatu Saloranta

unread,
Jul 22, 2019, 3:56:00 PM7/22/19
to jackson-user
I think one important thing that may be missing from Javadocs is that this setting ONLY affects the specific case of 1-argument constructors -- those are the only cases where there is ambiguity between "delegating" and "properties-based" creators.
This because "delegating" creator only works with one argument, whereas "properties" can work with any number (although 0-argument is sort of pointless).
[note: in theory N-argument creator could work as delegating if there are `@JacksonInject` annotations, but I think that possibility is currently ignored].

So perhaps your constructors just have more than 1 argument? If so, choice makes no difference.

My personal preference is to simply use explicit `@JsonCreator` for 1-argument case, and use no-arguments constructor of Module.

-+ Tatu +-
 
Reply all
Reply to author
Forward
0 new messages