jackson-module-kotlin: 2.12.x regression: no default no-arguments constructor found
I have this Kotlin object which parses an XML into a data class
:
object XmlTool {
@JvmStatic
fun parseXml(xml: String?): Product {
val xmlIn = XMLInputFactory.newInstance()
val factory = XmlFactory(xmlIn)
val xmlModule = JacksonXmlModule()
val mapper = XmlMapper(factory, xmlModule).registerKotlinModule()
return mapper.readValue(xml, Product::class.java)
}
data class Stuff(val str: String?)
data class Product(val stuff: Stuff?)
}
And this Java test:
class Jackson212MissingConstructorTest {
@Test
void fails_with_jackson_2_12() throws Exception {
String xml = "<product><stuff></stuff></product>";
Product product = XmlTool.parseXml(xml);
assertEquals(new Product(null), product);
}
}
Parsing this in Jackson 2.12.0 fails with com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of jackson.xml.XmlTool$Stuff (although at least one Creator exists): no default no-arguments constructor found
.
Jackson 2.11.3 works just fine.
The full exception is:
jackson.xml.Jackson212MissingConstructorTest > fails_with_jackson_2_12()
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `jackson.xml.XmlTool$Stuff` (although at least one Creator exists): no default no-arguments constructor found
at [Source: (StringReader); line: 1, column: 17] (through reference chain: jackson.xml.XmlTool$Product["stuff"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1590)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1215)
at com.fasterxml.jackson.databind.deser.ValueInstantiator.createUsingDefault(ValueInstantiator.java:248)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createUsingDefault(StdValueInstantiator.java:275)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.getEmptyValue(BeanDeserializerBase.java:1027)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmptyString(StdDeserializer.java:322)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromString(StdDeserializer.java:271)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1480)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:207)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:197)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:542)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:565)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:449)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1390)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:362)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:195)
at com.fasterxml.jackson.dataformat.xml.deser.XmlDeserializationContext.readRootValue(XmlDeserializationContext.java:91)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4568)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3523)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3491)
at jackson.xml.XmlTool.parseXml(XmlTool.kt:19)
at jackson.xml.Jackson212MissingConstructorTest.fails_with_jackson_2_12(Jackson212MissingConstructorTest.java:14)
Here’s a test project: https://github.com/henrik242/jackson-xml-problem/tree/2-12-empty-constructor
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 52 (28 by maintainers)
Commits related to this issue
- Add passing test for #427 — committed to FasterXML/jackson-dataformat-xml by cowtowncoder 4 years ago
- Add kotlin/xml related test that breaks Jackson 2.12.0 See https://github.com/FasterXML/jackson-module-kotlin/issues/396 — committed to henrik242/jackson-integration-tests by henrik242 4 years ago
- Add kotlin/xml related test that breaks Jackson 2.12.0 See https://github.com/FasterXML/jackson-module-kotlin/issues/396 — committed to henrik242/jackson-integration-tests by henrik242 4 years ago
- Add kotlin/xml related test that breaks Jackson 2.12.0 See https://github.com/FasterXML/jackson-module-kotlin/issues/396 — committed to henrik242/jackson-integration-tests by henrik242 4 years ago
- Add java/json/xml related test that breaks Jackson 2.12.x See https://github.com/FasterXML/jackson-module-kotlin/issues/396 — committed to henrik242/jackson-integration-tests by henrik242 3 years ago
- Fix "failing failing" test for #396 — committed to FasterXML/jackson-module-kotlin by cowtowncoder a year ago
- Update release notes wrt #396 being fixed — committed to FasterXML/jackson-module-kotlin by cowtowncoder a year ago
- Jackson212MissingConstructorTest should have worked in jackson 2.15 But it does not. Ref https://github.com/FasterXML/jackson-module-kotlin/issues/396 — committed to henrik242/jackson-integration-tests by henrik242 a year ago
@henrik242 I think I’ll first transfer this to Kotlin module, for maintainers to see.
Weird. It works out of the box in IntelliJ IDEA. Haven’t used Eclipse in ages, so I can’t help there 😕
EDIT: I tried the latest Eclipse IDE, but couldn’t get it to work. The kotlin plugin had problems that I was unable to resolve, and the scala plugin isn’t supported anymore.
@henrik242 I think release will be sooner than I originally planned, due to one particular CVE. But I think we are still out by at least a month since first release candidate. Still, lots of good fixes esp. for Java record types, for 2.15.
@henrik242 Thanks for following up with that—such links of information are very helpful.
I don’t think this is a Kotlin-specific problem. I have managed to reproduce the regression in the below Java snippet, which works in 2.11.4, but fails in 2.12.x:
Both tests pass on 2.11.4, whereas, on 2.12.x,
test_empty_Problem_JSON_deserialization()
passes andtest_empty_Problem_XML_deserialization()
fails with the following message:In order to make
test_empty_Problem_XML_deserialization()
pass on 2.12.x, one needs to add a no-arg ctor toDefaultProblem
.@patrick-dedication A minimal example (or a failing test) is always good to have! Interesting that you have found the same issue with JSON.
No fix in 2.12.2 either
@cowtowncoder We actually already have the
jackson-dataformat-xml
module in the Kotlin module’s test dependencies, so I added @henrik242 's test to this module’s test suite.I haven’t dug into what’s actually going wrong, happy to take tips or PRs against that branch for a fix.
@cowtowncoder @michaelbrewer @dinomite I’ve added an integration test for this now
Typically first .1 patch follows in about 1 month of the .0, depending on accumulation of fixes. I am trying to take it easy over December anyway, but I think it is likely that 2.12.1 would be released around end of 2020, either last week of Dec or first of Jan 2021.
As to regression test: if the test requires both XML and Kotlin modules, it should to go in:
https://github.com/FasterXML/jackson-integration-tests
to avoid adding cross-component dependencies (beyond existing compile-time dependencies to core components). This assuming it is not possible to reproduce this without xml module (or kotlin module).
@cowtowncoder @dinomite The 2.12 release fails with this issue now.