Skip to content

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

Closed

Description

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

Activity

  1. added
    3.xSomething that likely has to be done in 3.x, not 2.x
    on Jul 31, 2021
  2. pjfanning commented on Sep 29, 2021

    @pjfanning
    MemberAuthor

    @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.

  3. pjfanning commented on Sep 29, 2021

    @pjfanning
    MemberAuthor

    @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

  4. cowtowncoder commented on Oct 2, 2021

    @cowtowncoder
    Member

    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.

  5. pjfanning commented on Oct 2, 2021

    @pjfanning
    MemberAuthor

    @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.

  6. cowtowncoder commented on Oct 2, 2021

    @cowtowncoder
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xSomething that likely has to be done in 3.x, not 2.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions