jackson-module-scala icon indicating copy to clipboard operation
jackson-module-scala copied to clipboard

investigate test code that passes in jackson-module-scala v2 but not in v3

Open pjfanning opened this issue 4 years ago • 5 comments

  • look for //TODO fix in test code
  • currently just 2 cases left

pjfanning avatar Jul 31 '21 20:07 pjfanning

@cowtowncoder there is a test that is failing in jackson v3 but not in v2.

  class Sample1 {
    @JsonProperty("v") var value: Int = 0
  }

When I try to deserialize {"v": 1} - this passes in jackson 2.13 - but in v3, it fails with:

[info] - should support JsonProperty annotation *** FAILED ***
[info]   java.lang.IllegalStateException: Conflicting/ambiguous property name definitions (implicit name 'value'): found multiple explicit names: [v, value], but also implicit accessor: [method com.fasterxml.jackson.module.scala.deser.JsonPropertyTest$Sample1#getValue()][visible=true,ignore=false,explicitName=false]
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._explode(POJOPropertyBuilder.java:1150)
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.explode(POJOPropertyBuilder.java:1129)
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._renameProperties(POJOPropertiesCollector.java:908)
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:368)
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:335)
[info]   at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:185)
[info]   at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:157)
[info]   at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:224)
[info]   at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:285)
[info]   at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:229)

jackson-module-scala v2 and v3 has very similar code in its AnnotationIntrospector.

The jackson-databind v3 code for collecting properties (POJOPropertyBuilder) has changed quite a lot in v3.

I could try hacking at the fields, getters and setters that the Scala module code exposes to jackson-databind but I fear this will cause more issues than it solves.

A similar test in java works ok so the issue only happens with jackson-module-scala.

One of the oddities of Scala is the val value is simultaneously a field, a getter and a setter.

pjfanning avatar Sep 29 '21 10:09 pjfanning

@cowtowncoder I hacked a fix in jackson-module-scala v3 - it now needs to check the JsonProperty annotation itself instead of relying on jackson-databind to do that

pjfanning avatar Sep 29 '21 15:09 pjfanning

Hmmh. That is unfortunate, assuming it by-passes AnnotationIntrospector? -- but whatever is needed I suspect. Databind should combine annotation info across field, getter and setter but perhaps this is where name linking is not detected for some reason.

cowtowncoder avatar Oct 02 '21 15:10 cowtowncoder

@cowtowncoder the change I made was in the Scala AnnotationIntrospector. It should be ok to just leave the v3/master code as is since the test case passes now.

pjfanning avatar Oct 02 '21 19:10 pjfanning

Ah ok. That makes sense then -- I just want to try to avoid code from outside an AnnotationIntrospector from directly checking annotations; overloaded variants like Scala's are definitely allowed to introspect annotations.

cowtowncoder avatar Oct 02 '21 22:10 cowtowncoder