You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
investigate test code that passes in jackson-module-scala v2 but not in v3ย #536
@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.
@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
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 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.
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.
Activity
pjfanning commentedon Sep 29, 2021
@cowtowncoder there is a test that is failing in jackson v3 but not in v2.
When I try to deserialize
{"v": 1}- this passes in jackson 2.13 - but in v3, it fails with: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 valueis simultaneously a field, a getter and a setter.pjfanning commentedon Sep 29, 2021
@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 commentedon Oct 2, 2021
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 commentedon Oct 2, 2021
@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 commentedon Oct 2, 2021
Ah ok. That makes sense then -- I just want to try to avoid code from outside an
AnnotationIntrospectorfrom directly checking annotations; overloaded variants like Scala's are definitely allowed to introspect annotations.