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.

Cannot deserialize node with mixed context

See original GitHub issue

Xml node with mixed content throws exception when content in particular order: suppose we have classes:

@Serializable
data class Tree(val node1: Node1)

@Serializable
@SerialName("node1")
data class Node1(
    @XmlValue(true) val text: String = "",
    val subnode1: Subnode1
)

@Serializable
@SerialName("subnode1")
data class Subnode1(@XmlValue(true) val text: String)

this xml can be deserialized:

<tree>
   <node1>
       <subnode1> text1 </subnode1>
           some text here
   </node1>
</tree>

but if we swap subnode1 and some text:

<tree>
   <node1>
        some text here
       <subnode1> text1 </subnode1>
   </node1>
</tree>

exception is thrown: Exception in thread "main" nl.adaptivity.xmlutil.XmlException: Found unexpected child tag

gist: here

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pdvriezecommented, Nov 21, 2019

The easiest example is in the test suite: https://github.com/pdvrieze/xmlutil/blob/9c67201298c61c209e818c5b3eca0eb5b5ecb3fc/serialization/src/commonTest/kotlin/nl/adaptivity/xml/serialization/testClasses.kt#L140-L150 Note that it requires all other properties to be attributes. You will also have to create a serial module. From a safety perspective it is advisable to add the string case to the module.

If you do not use Any as the base class string content may create issues with the string content still being added to the list. I have not put in any code that handles ignorable whitespace when we can’t handle it.

0reactions
underlowcommented, Nov 20, 2019

can you please provide an example if possible? Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deserialize element value as string although it contains mixed ...
P.S. Just to explain "the why?". I have a class witch gets serialized. The serialized XML then travels through multiple nodes in the...
Read more >
XMLSerializer don't handle mixed contents properly - MSDN
I have seen the Microsoft code to serialize/deserialize the xml through reflector. They put text in a string array but position is not...
Read more >
How to Deserialize JSON Into Dynamic Object in C# - Code ...
Describe how to deserialize JSON into dynamic object in C# with detail explanation and examples using native and Newtonsoft library.
Read more >
[Solved]-HTMLAgility Pack: Replacing content in a "mixed-type ...
HtmlNode constructor creates a node of type HtmlNode (but sets the type of the node to the value passed). When you want to...
Read more >
Deserialization with System.Text.Json - Marc Roussy
You need full control of how and what you're going to deserialize. · You have a really large JSON document that can't feasibly...
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