jackson-modules-java8 icon indicating copy to clipboard operation
jackson-modules-java8 copied to clipboard

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

Open clo-vis opened this issue 4 years ago • 4 comments

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) { }
}

clo-vis avatar Jun 25 '20 11:06 clo-vis

Interesting. Sounds like a flaw.

cowtowncoder avatar Oct 20 '20 02:10 cowtowncoder

Can reproduce the issue; added a failing test.

cowtowncoder avatar Oct 20 '20 05:10 cowtowncoder

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 avatar Oct 20 '20 05:10 cowtowncoder

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

cowtowncoder avatar Nov 10 '20 17:11 cowtowncoder

Was fixed in jackson-databind 2.12.0, actually.

cowtowncoder avatar Sep 24 '22 03:09 cowtowncoder