-
-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
Milestone
Description
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:
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
Metadata
Metadata
Assignees
Labels
No labels