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.

System.Text.Json Json serialization / deserialization fails

See original GitHub issue

Description Stylet/PropertyChangedBase.cs is missing the attribute [System.Text.Json.Serialization.JsonIgnore] to make classes serializable and deserializable.

To Reproduce

public class Test : Stylet.PropertyChangedBase
{
 public string TestString {get; set; }
}

can be serialized, but has a "PropertyChangedDispatcher": {} object which can’t be deserialized.

Version Info

  • Stylet version: 1.3.6
  • Runtime version: 6.0.1

**Solution **

[System.Xml.Serialization.XmlIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public virtual Action<Action> PropertyChangedDispatcher
{
    get { return this._propertyChangedDispatcher; }
    set { this._propertyChangedDispatcher = value; }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Catalan-1apcommented, Mar 30, 2022

Description Stylet/PropertyChangedBase.cs is missing the attribute [System.Text.Json.Serialization.JsonIgnore] to make classes serializable and deserializable.

To Reproduce

public class Test : Stylet.PropertyChangedBase
{
 public string TestString {get; set; }
}

can be serialized, but has a "PropertyChangedDispatcher": {} object which can’t be deserialized.

Version Info

  • Stylet version: 1.3.6
  • Runtime version: 6.0.1

**Solution **

[System.Xml.Serialization.XmlIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public virtual Action<Action> PropertyChangedDispatcher
{
    get { return this._propertyChangedDispatcher; }
    set { this._propertyChangedDispatcher = value; }
}

You could serialize only what you want. Just mark your class with [JsonObject(MemberSerialization.OptIn)] and properties to serialize with [JsonProperty].

For more info see docs

0reactions
canton7commented, Apr 3, 2022

(this will be closed when the next release is merged)

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Text.Json Deserialize Fails - net core
I was getting an error about Unable to Parse without a parameterless constructor. I have since fixed that, but now my objects are...
Read more >
System.Text.Json fails to deserialize into a model with an ...
Text.Json serializer. While the code appears to be a valid application of the general principles of System.Text.Json, it fails in practice. It ...
Read more >
System.Text.Json - can't serialize exception #43026
Description We're trying to use System.Text.Json for serialization and deserialization inside our API project with GraphQL.
Read more >
How to serialize and deserialize JSON using C# - .NET
This article shows how to use the System.Text.Json namespace to serialize to and deserialize from JavaScript Object Notation (JSON).
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Newtonsoft.Json can serialize or deserialize numbers represented by JSON strings (surrounded by quotes). For example, it can accept: {" ...
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