jsonconverter

Deserialize complex polymorphic types with System.Text.Json

老子叫甜甜 提交于 2021-02-11 13:39:15
问题 The dotnet example in the documentation: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to#support-polymorphic-deserialization shows manually parsing each property of a polymorphic type. However: my polymorphic objects are complex deep hierarchies, I can't hand code every field so I need to invoke the JsonSerializer . the clue for the type is specified in sibling fields. Given there is no guarantee about json element order, a Utf8JsonReader may

Custom JSON Deserialization in C# with JsonConverter

孤街醉人 提交于 2021-02-11 06:51:10
问题 I have two classes in .Net Core The class Ownership namespace CustomStoreDatabase.Models { public class Ownership { public string OwnershipId { get; set; } public List<string> TextOutput { get; set; } public DateTime DateTime { get; set; } public TimeSpan MeanInterval { get; set; }// Like long ticks, TimeSpan.FromTicks(Int64), TimeSpan.Ticks } } I need to show MeanInterval like long ticks, using the methods TimeSpan.FromTicks(Int64) and TimeSpan.Ticks . My custom JsonConverter using

Converting json to c# object

*爱你&永不变心* 提交于 2019-12-25 03:13:34
问题 I have an api that returns me a json with information about the data transition and an array with data { "code": "200", "result": true, "message": "", "data": { "item": [ { "id": "5", "descricao": "TesteDesc", "observacao": "TesteObs", "status": "1" }, { "id": "7", "descricao": "TesteDesc", "observacao": "TesteObs", "status": "1" }, ], "count": 2 } } I have a class that is referring to the return of items class Category { public int Id { get; set; } public string Descricao { get; set; }

Token PropertyName in state Property would result in an invalid JSON object. when using custom JsonConverter<T>

Deadly 提交于 2019-12-02 00:20:15
问题 I am trying to serialise/deserialise a .NET DataSet using Json.NET and a custom serialiser. I know many of you will tell me not to (I have seen this on other posts) I have a valid reason and wish to continue down this route. My serialisation is based upon the fact that the .NET DataSet can export it's schema and data to XML and then re-import the same; on that basis, I am trying to create a converter that will allow me to capture that XML, convert it to JSON then convert it back and reload it

Token PropertyName in state Property would result in an invalid JSON object. when using custom JsonConverter<T>

六眼飞鱼酱① 提交于 2019-12-01 21:14:59
I am trying to serialise/deserialise a .NET DataSet using Json.NET and a custom serialiser. I know many of you will tell me not to (I have seen this on other posts) I have a valid reason and wish to continue down this route. My serialisation is based upon the fact that the .NET DataSet can export it's schema and data to XML and then re-import the same; on that basis, I am trying to create a converter that will allow me to capture that XML, convert it to JSON then convert it back and reload it. My implementation is as follows... class DataSetConverter : JsonConverter<DataSet> { public override