FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
401 stars 117 forks source link

jackson-module-parameter-names: @JsonPropertyName still required if @JsonDeserialize is used #178

Closed clo-vis closed 2 years ago

clo-vis commented 4 years ago

If ParameterNamesModule is registered, { "a": 1, "b": 1 } can be deserialized to an instance of:

public class Foo{
     public Foo(int a, int b) { }
}

but not to an instance of:

public class Foo{
    public Foo(@JsonDeserialize(converter=Incr.class) int a, int b) { }
}

unless you declare the property name again:

public class Foo{
     public Foo(@JsonDeserialize(converter=Incr.class)@JsonProperty("a") int a, int b) { }
}
cowtowncoder commented 4 years ago

Interesting. Sounds like a flaw.

cowtowncoder commented 4 years ago

Can reproduce the issue; added a failing test.

cowtowncoder commented 4 years ago

Ah. I think I know the root cause: existence of a few "well-known" annotation triggers equivalent of returning empty String for name for (de)serialization -- meaning "use default". But I think creator detection logic does not realize this (as it is abstracted behind AnnotationIntrospector)... and that needs to change, somehow. Fix needs to be in jackson-databind, but issue can be here for now.

cowtowncoder commented 3 years ago

Created https://github.com/FasterXML/jackson-databind/issues/2932 -- unlikely to be resolved for 2.12, hope to address in 2.13.

cowtowncoder commented 2 years ago

Was fixed in jackson-databind 2.12.0, actually.