question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Input mismatch with case-insensitive properties ('MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES')

See original GitHub issue

Besides 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: image

Second element, notice the nextToken is null image

Third rogue context who is apparently child to Element 😕 image

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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Dec 6, 2017

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

0reactions
cowtowncodercommented, May 12, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found