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.

Partial deserialization.

See original GitHub issue

With v3.1.4, I receive the following XML from an external web source:

<?xml version="1.0" encoding="UTF-8"?>
<pin>
  <id type="integer">1309801580</id>
  <code>GBCT</code>
  <expires-at type="dateTime">2020-05-10T18:52:14Z</expires-at>
  <user-id type="integer">231221</user-id>
  <client-identifier>8c89f40c-e1f3-45e1-95bc-a45a047ce77f</client-identifier>
  <trusted type="boolean">false</trusted>
  <auth-token>z6ZM5jeSP19WroEQc2Xy</auth-token>
  <auth_token>z6ZM5jeSP19WroEQc2Xy</auth_token>
</pin>

the provided class for it is:

[XmlRoot("pin")]
public sealed class Pin
{
        [XmlElement("id")]
        public int ID { get; set; }

        [XmlElement("code")]
        public string Code { get; set; }

        [XmlElement("expires-at")]
        public DateTime ExpiresAtUTC { get; set; }

        [XmlElement("auth-token")]
        public string AuthToken { get; set; }

        [XmlElement("client-identifier")]
        public Guid ClientIdentifier { get; set; }
}

I instantiate the serializer and deserialize with the following. This is a piece of the method who except a generic TReturn type. In this case, a Pin class.

string xml = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

IExtendedXmlSerializer serializer = new ConfigurationContainer().EnableImplicitTypingFromNamespace<Pin>().Create();
using (StringReader stringReader = new StringReader(xml))
{
        returnObj = (TReturn)serializer.Deserialize<TReturn>(stringReader);
}

Every property of the resulting class is populated correctly, except AuthToken who is always empty. Is it a bug, or something I do wrong?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Mike-E-angelocommented, May 11, 2020

Alright I have added a new section to our wiki here, for your review:

https://github.com/ExtendedXmlSerializer/home/wiki/Example-Scenarios#unknown-content

<div> GitHub</div><div>ExtendedXmlSerializer/home</div><div>A highly configurable and eXtensible Xml serializer for .NET. - ExtendedXmlSerializer/home</div>
1reaction
sbeaudoincommented, May 11, 2020

Thank you for the fast answer. I sincerely tried to find this “switch” myself for a few hours. Even now, if I search WithUnknownContent in the API reference, nothing come in the result. I will try this library a little longer, in evaluation mode this time, hoping the documentation will be updated soon. The main reason I use it is for the support of Enums, particularly, I am hoping it support Flags Enums.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improving data processing efficiency using partial ...
A significant portion of that processing involves deserializing Thrift structures from serialized bytes on disk. It costs us significant amounts ...
Read more >
Deserializing Partial JSON Fragments
Deserializing Partial JSON Fragments ... Often when working with large JSON documents you're only interested in a small fragment of information. This scenario...
Read more >
How to do a partial deserialization with Jackson - java
The simplest approach would be using JsonNode : @Data public class FullAddress { private String address; private JsonNode contactInfo; }.
Read more >
Can you partial deserialize a Vec? : r/learnrust
Hello, So I am deserializing JSON responses and was wondering if serde can do partial deserialization. For example: Let's say I get back...
Read more >
Partial deserialization · Issue #1154 · serde-rs/serde
Is it possible to deserialize structure partially (i.e. something like serde_json::Value but generic across formats).
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