-
Notifications
You must be signed in to change notification settings - Fork 175
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
Unable to deserialize missing XML tag to null #461
Comments
I think this might be Kotlin-specific, so moving. One question: is this with Jackson 2.12(.3) or earlier? 2.12 added a few improvements to null handling, although I suspect this issue may be wrt Delegating-vs-Properties-based creators. |
Thanks! This is with 2.12.3. Also, one of the test cases ( |
Tried on branch 2.16 but could not reproduce, so it is closed. import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
import com.fasterxml.jackson.dataformat.xml.XmlFactory
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.fasterxml.jackson.module.kotlin.test.github.XmlTool.Inner
import com.fasterxml.jackson.module.kotlin.test.github.XmlTool.Outer
import com.fasterxml.jackson.module.kotlin.test.github.XmlTool.Root
import com.fasterxml.jackson.module.kotlin.test.github.XmlTool.parseOuter
import com.fasterxml.jackson.module.kotlin.test.github.XmlTool.parseRoot
import junit.framework.TestCase.assertEquals
import javax.xml.stream.XMLInputFactory
import kotlin.test.Test
object XmlTool {
val xmlIn = XMLInputFactory.newInstance()
val factory = XmlFactory(xmlIn)
val xmlModule = JacksonXmlModule()
val mapper = XmlMapper(factory, xmlModule)
.registerKotlinModule()
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) // Doesn't make any difference
@JvmStatic
fun parseRoot(xml: String?): Root = mapper.readValue(xml, Root::class.java)
@JvmStatic
fun parseOuter(xml: String?): Outer = mapper.readValue(xml, Outer::class.java)
data class Inner(val code: String?)
data class Outer(val inner: Inner?)
data class Root(val outer: Outer?)
}
class Github461 {
@Test
fun no_string_argument() {
val xml = "<root>" +
" <outer>" +
" <inner code=\"578\" />" +
" </outer>" +
"</root>"
val product = parseRoot(xml)
assertEquals(Root(Outer(Inner("578"))), product) // SUCCESS
}
@Test
fun no_string_argument2() {
val xml = "<outer>" +
"</outer>"
val product = parseOuter(xml)
assertEquals(Outer(null), product) // SUCCESS in Jackson 2.11.3, but FAIL in 2.12.3
}
@Test
fun no_string_argument3() {
val xml = "<root>" +
" <outer>" +
" </outer>" +
"</root>"
val product = parseRoot(xml)
assertEquals(Root(Outer(Inner(null))), product) // Always FAILS
}
} |
Related problem from 2.12.3 and onwards: #721 |
I have a simple parser and data structure (Kotlin):
.. and a test (Java):
The last test fails with the following exception:
What do I need to change to make this test pass?
I have created a test project at https://github.com/henrik242/jackson-xml-problem/tree/no-string-argument
The text was updated successfully, but these errors were encountered: