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.

Question: Deserializing with unknown content

See original GitHub issue

After reading the wiki at: https://github.com/ExtendedXmlSerializer/home/wiki/Example-Scenarios#unknown-content

It does not look like it is working correctly for me.

I was testing the WithUnknownContent() option because an xml document changed and some fields are now deprecated. Hopefully this can easily solve the problem without using Xslt.

But before I got there I noticed something strange with WithUnknownContent() when trying it out on an xml file without any unknown content.

var configurationContainer = new ConfigurationContainer()
  .EnableImplicitTyping(typeof(InputModel))
  .Create();
var inputModel = configurationContainer.Deserialize<InputModel>(new XmlReaderSettings { IgnoreWhitespace = false }, inputXml);

var configurationContainer2 = new ConfigurationContainer()
  .EnableImplicitTyping(typeof(InputModel))
  .WithUnknownContent()
  .Continue()
  .Create();
var inputModel2 = configurationContainer2.Deserialize<InputModel>(new XmlReaderSettings { IgnoreWhitespace = false }, inputXml);

I tried the above configurationContainers to deserialize an xml file without unknown content but noticed the deserialization no longer works when I add WithUnknownContent(). For var inputModel the deserialization works. For var inputModel2 the deserialization does not work.

Any idea why the deserialization stops working when I add WithUnknownContent?

Let me know if you need the InputModel class or an example XML file.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
josdemmerscommented, Nov 26, 2021

Just tested WithUnknownContent with some deprecated properties in my xml files, works perfect. Deprecated properties are ignored and next elements are added without any problem!

0reactions
josdemmerscommented, Nov 27, 2021

Thanks again, that answers my question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Deserializing an unknown type in JSON.NET
I just got a hold of JSON.NET and its been great so far. However, I cannot figure out how to determine the type...
Read more >
SerializationException: There was an error deserializing ...
I have just started making an app (following someone) using a movie API from tmdb. There appears to be an issue with the...
Read more >
Jackson Unmarshalling JSON with Unknown Properties
In this article, we discussed deserializing a JSON with additional, unknown properties using Jackson. This is one of the most common things to ......
Read more >
JSON.deserialize not ignoring unknown properties.
During deserialization json try to assign values to product__c which is not a Apex class, it is a sobject so in that case...
Read more >
deserializeStrict method: bug?
When deserializing JSON content with extraneous attributes into an Apex class, this method throws an exception in all API versions. However, no ...
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