Skip to content

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

Closed
@cowtowncoder

Description

@cowtowncoder

(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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions