Input mismatch with case-insensitive properties ('MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES')
See original GitHub issueBesides the #252 I tried to adapt my XML to nonself-closing, some preprocessing is always good 🃏 Issue is somewhat similar to #255
My XML provider, accurev is not very friendly. I would very much like to abstract as much XML as possible. Sadly when case insensitivity is turned on the XML mapper it seems to add a rogue element. In this case, it treats a “/” as an Element that then needs to chuck through to Depot class but chokes because of a null pointer.
I can easily treat the symptom by adding a null pointer check for JsonToken however I would like to know the root cause.
First element is detected like this:
Second element, notice the nextToken is null
Third rogue context who is apparently child to Element 😕
Caused by: java.lang.NullPointerException
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:168)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:285)
fun main(args : Array<String>) {
val bob = "hello world"
val xml = """
<?xml version="1.0" encoding="utf-8"?>
<AcResponse
Command="show depots"
TaskId="1260">
<Element
Number="1"
Name="accurev"
Slice="1"
exclusiveLocking="false"
case="insensitive"
locWidth="128"></Element>
<Element
Number="2"
Name="second accurev"
Slice="2"
exclusiveLocking="false"
case="insensitive"
locWidth="128"></Element>
</AcResponse>""".trimIndent()
val mapper : ObjectMapper = XmlMapper()
mapper.registerModule(KotlinModule())
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
val response : Depots = mapper.readValue(xml)
println(response)
}
data class Depots(
val command: String,
val taskId: String,
@JacksonXmlElementWrapper(useWrapping = false)
var element: ArrayList<Depot>
)
@JsonIgnoreProperties(ignoreUnknown = true)
data class Depot(
@JacksonXmlProperty(isAttribute = true)
val number : String = "",
@JacksonXmlProperty(isAttribute = true)
val name : String = ""
)
Full stack trace
Caused by: com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.jenkinsci.plugins.accurevclient.model.Depots["element"]->java.util.ArrayList[2])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:391)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:363)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:306)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:519)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:527)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:416)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1265)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:325)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.dataformat.xml.deser.WrapperHandlingDeserializer.deserialize(WrapperHandlingDeserializer.java:113)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3011)
at org.jenkinsci.plugins.accurevclient.PlayGroundKt.main(PlayGround.kt:40)
... 5 more
Caused by: java.lang.NullPointerException
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:168)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:161)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:285)
... 17 more
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to deserialise JSON string to object relaxing root value ...
I would like to support both upper and lower case. We have below Jackson configurations which works fine for properties and enums but...
Read more >MapperFeature (jackson-databind 2.12.3 API) - javadoc.io
Feature that determines whether properties that have no view annotations are included in JSON serialization views (see JsonView for more details on JSON...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@casz Understandable: purely considering XML part, JAXB is awesome lib/framework, since it started with and focuses solely on XML. I hope this problem (and related) can be solved as well as there’s on the other hand lots of potential being able to cross formats, languages and datatypes.
Having another look at this, finally. I think I know where to look now: chances are this has to do with unwrapped Lists; probably start/end tag matching is not doing case-insensitivity as it should.
But the tricky part is, maybe surprisingly, that low-level XML parser (streaming API impl) has no concept of case-insensitivity, yet, all handled (currently) at databind layer. But will see if knowledge is necessary or if it’d be possible to just rely on matching of start/end elements instead.