system.text.json

How to ignore false values with System.Text.Json

我的梦境 提交于 2020-12-09 03:56:51
问题 I'm migrating from Newtonsoft.Json to System.Text.Json in my .NET Core 3.0 application. I'm trying to ignore false values. In System.Text.Json I found the option to ignore null values: JsonSerializerOptions.IgnoreNullValues = true; But I cannot find the option to ignore false values in System.Text.Json . Does someone know how can this be achieved with System.Text.Json ? Or if someone know the equivalent of Newtonsoft DefaultValueHandling = DefaultValueHandling.Ignore option that would be

Read value from dynamic property from json payload

China☆狼群 提交于 2020-11-29 10:51:48
问题 I have a simple model that I used as a request payload public class CommandRequest { public CommandType Type { get; set; } public dynamic Attributes { get; set; } } In controller action I need to read some property from dynamic Attributes public async Task<IActionResult> Commands([FromBody] CommandRequest requestBody) { string name = requestBody.Attributes.Name; ... } Got the following exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Text.Json.JsonElement' does not

Read value from dynamic property from json payload

情到浓时终转凉″ 提交于 2020-11-29 10:50:05
问题 I have a simple model that I used as a request payload public class CommandRequest { public CommandType Type { get; set; } public dynamic Attributes { get; set; } } In controller action I need to read some property from dynamic Attributes public async Task<IActionResult> Commands([FromBody] CommandRequest requestBody) { string name = requestBody.Attributes.Name; ... } Got the following exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Text.Json.JsonElement' does not