Cannot deserialize node with mixed context
See original GitHub issueXml 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:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top 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 >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
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.can you please provide an example if possible? Thank you