Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pjfanning opened this issue Jul 31, 2021 · 5 comments
Labels
3.x Something that likely has to be done in 3.x, not 2.x

Comments

@pjfanning
Copy link
Member

  • look for //TODO fix in test code
  • currently just 2 cases left
@pjfanning pjfanning added the 3.x Something that likely has to be done in 3.x, not 2.x label Jul 31, 2021
@pjfanning
Copy link
Member Author

pjfanning commented Sep 29, 2021

@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
Copy link
Member Author

@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

@cowtowncoder
Copy link
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.

@pjfanning
Copy link
Member Author

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

@cowtowncoder
Copy link
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
Labels
3.x Something that likely has to be done in 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

2 participants