system.text.json

System.Text.Json Merge two objects

左心房为你撑大大i 提交于 2021-02-18 12:11:29
问题 Is it possible to merge two json objects like this with System.Text.Json? Object 1 { id: 1 william: "shakespeare" } Object 2 { william: "dafoe" foo: "bar" } Result Object { id: 1 william: "dafoe" foo: "bar" } I am able to achieve it with newtonsoft.json like this var obj1 = JObject.Parse(obj1String); var obj2 = JObject.Parse(obj2String); obj1.Merge(obj2); result = settings.ToString(); But is there a way with System.Text.Json ? 回答1: As of .Net Core 3.0 merging of JSON objects is not

System.Text.Json Merge two objects

最后都变了- 提交于 2021-02-18 12:10:32
问题 Is it possible to merge two json objects like this with System.Text.Json? Object 1 { id: 1 william: "shakespeare" } Object 2 { william: "dafoe" foo: "bar" } Result Object { id: 1 william: "dafoe" foo: "bar" } I am able to achieve it with newtonsoft.json like this var obj1 = JObject.Parse(obj1String); var obj2 = JObject.Parse(obj2String); obj1.Merge(obj2); result = settings.ToString(); But is there a way with System.Text.Json ? 回答1: As of .Net Core 3.0 merging of JSON objects is not

Query or deserialize json with dynamic keys using System.Text.Json

╄→гoц情女王★ 提交于 2021-02-17 02:48:30
问题 I have json that looks like this, the key "123" could be any number. { "key1": "", "key2": { "items": { "123": { "pageid": 123, "name": "data" } } } } I want to deserialize or query the json with System.Text.Json so i can get the value of the key "name". How can I do that with System.Text.Json? I'm using .NET Core 3.1. 回答1: Something like: public class Rootobject { public string key1 { get; set; } public InnerObject key2 { get; set; } } public class InnerObject { public Dictionary<string,

Why does System.Text Json Serialiser not serialise this generic property but Json.NET does?

天大地大妈咪最大 提交于 2021-02-16 18:17:05
问题 I have the following situation. I have simplified the problem into the following example, although my real situation is more complicated. System.Text.Json does not serialise the object fully but Newtonsoft Json.NET does. Suppose I have the following class structure. public class A { public string AProperty { get; set; } = "A"; } public class A<T> : A where T : class, new() { public T TObject { get; set; } = new T(); } public class B { public string BProperty { get; set; } = "B"; } public

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

Partial deserialization Web API Core controller

点点圈 提交于 2021-02-11 06:13:12
问题 I have an object defined as such public class FilingSearchCriteria { public int? FilerId { get; set; } public int? TypeId { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public bool? Legacy { get; set; } public bool? NoAtttachments { get; set; } public bool? MissingFields { get; set; } public bool? MissingAttachments { get; set; } public string DocketNumber { get; set; } } A a Net Core controller takes it as a parameter. Issue is most of the time

Partial deserialization Web API Core controller

孤街醉人 提交于 2021-02-11 06:11:56
问题 I have an object defined as such public class FilingSearchCriteria { public int? FilerId { get; set; } public int? TypeId { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public bool? Legacy { get; set; } public bool? NoAtttachments { get; set; } public bool? MissingFields { get; set; } public bool? MissingAttachments { get; set; } public string DocketNumber { get; set; } } A a Net Core controller takes it as a parameter. Issue is most of the time

Partial deserialization Web API Core controller

≡放荡痞女 提交于 2021-02-11 06:10:25
问题 I have an object defined as such public class FilingSearchCriteria { public int? FilerId { get; set; } public int? TypeId { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public bool? Legacy { get; set; } public bool? NoAtttachments { get; set; } public bool? MissingFields { get; set; } public bool? MissingAttachments { get; set; } public string DocketNumber { get; set; } } A a Net Core controller takes it as a parameter. Issue is most of the time

Partial deserialization Web API Core controller

不羁岁月 提交于 2021-02-11 06:10:05
问题 I have an object defined as such public class FilingSearchCriteria { public int? FilerId { get; set; } public int? TypeId { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public bool? Legacy { get; set; } public bool? NoAtttachments { get; set; } public bool? MissingFields { get; set; } public bool? MissingAttachments { get; set; } public string DocketNumber { get; set; } } A a Net Core controller takes it as a parameter. Issue is most of the time