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

Consider selecting Mode.DELEGATING for Map-valued 1-arg constructors #4911

Closed
cowtowncoder opened this issue Jan 16, 2025 · 1 comment
Closed

Comments

@cowtowncoder
Copy link
Member

(note: created from FasterXML/jackson-module-kotlin#846)

1-argument constructors are fundamentally ambiguous: for example, POJO like:

public class Bean {
   @JsonCreator
   public Bean(String key) { ... }
}

could be expected to match either JSON String like

"value"

OR JSON Object

{ "key": "value" }

where first case is "Delegating" (full JSON value is Delegated as-is) and second case "Properties-based" (since incoming Object's property/properties are matched into separate properties -- 1-argumenet case is just a special case).

So Jackson has to use heuristics to decide which one to use. There are a few hints being checked (such as existence of @JsonValue strongly suggesting Delegating case; and existence of Field/setter/getter with name matching argument name suggesting Properties based case).

It sounds like behavior changed from 2.17 to 2.18, at least for Kotlin module, in a way that formerly Delegating cases were now decided as Properties-ones.
But it might be possible to change that heuristics such that if the parameter type is java.util.Map, chances are we have Delegating case (could extend to consider Collection and/or JsonNode as well).

@cowtowncoder
Copy link
Member Author

I am unable to reproduce the problem, unfortunately. Map valued 1-param @JsonCreator annotated constructor is indeed detected as DELEGATING in most cases. Only exception is the case where there is public field with same name as implicit parameter to Map-valued argument.

Closing: will need actual reproduction, can't do anything without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant