Closed Digital-Composition closed 1 year ago
Why would you need to check both options, these should be radio buttons instead but you need to choose only one option
@Json2CSharp the tool is very useful as it is. Yet, I package model libraries for references across a big system. Because the system I use is massive, some times JsonNewtonsoft and .Net libraries are used in different parts of the system. For instance, if I use Dependency Injection and I add HttpClient services (Default), the ReadFromJsonBody method that is offered uses .Net library so I'm stuck with JsonPropertyName attributes if I want to deserialize a Json object. So it would be beneficial for some developers to have that duality of model attributes just in cae it is necessary.
can you please provide an example output of what you want?
@Json2CSharp, in this example a developer has used Newtonsoft library to convert an XML formatted string into JSON string to be deserialized and used as an object. The developer uses a reference to a packaged library that has the company's most common models. Because the JSON is the result of an XML transformation, some properties have "@" symbol attached to the property name which requires a property name declaration to be deserialized correctly (JsonProperty).
Newtonsoft
XmlDocument doc = new XmlDocument();
doc.LoadXml(message);
string jsonText = JsonConvert.SerializeXmlNode(doc);
var payload = JsonConvert.DeserializeObject<Data>(jsonText);
Now the same model library is used in another project and that uses .NET library to handle JSON objects such as case of the default HttpClient class. So it would be beneficial to have the possibility to check both options "JsonProperty" and "JsonProperyName" when converting a JSON payload into C# data model.
System.Text.Json (.NET)
var content = await httpResponse.Content.ReadFromJsonAsync<Data>();
MODEL
public class Data
{
[JsonProperty("@updateTime")]
[JsonPropertyName("@updateTime")]
public string UpdateTime { get; set; }
[JsonProperty("Content")]
[JsonPropertyName("Content")]
public string Content { get; set; }
}
Ok I got it, so we will allow the two options for JsonProperty as well as for JsonPropertyName
@Json2CSharp a million thanks. I asked everybody in my team to disable Ad-blocker in your website to help the cause 😄
Thanks a lot ❤️ !!!
This is done, thanks for letting me know 👍
Despite the having the option to check both attributes, only one (JsonPropertyName) is selected. It would be so handy if I could add both attributes.