Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for System.Text.Json.Serialization.JsonPropertyNameAttribute ? #766

Closed
dennisvanderpool opened this issue Feb 13, 2022 · 1 comment
Labels

Comments

@dennisvanderpool
Copy link

using System.Text.Json.Serialization;
using Newtonsoft.Json;

public class SampleClass
    {
        [JsonPropertyName("base_currency")]    // Does not work (System.Text.Json.Serialization)
        [JsonProperty("base_currency")]        // Does work (Newtonsoft.Json)
        public string BaseCurrency { get; set; }
@AArnott
Copy link
Member

AArnott commented Feb 15, 2022

The attributes that are honored are based on the serializer in use, which is determined by the formatter you choose. This library comes with two formatters: JsonMessageFormatter (Newtonsoft.Json) and MessagePackFormatter (MessagePack). Neither of these honor System.Text.Json attributes as they are associated with a different serializer. However, both of these formatters (or rather, their underlying serializers) honor the DataContractSerializer attributes (DataContract, DataMember), so maybe the System.Text.Json serializer would honor them too, if you were hoping for one attribute that would work in multiple cases.

As another option, you could write a System.Text.Json-based formatter for this library. We looked into this previously (#305) but didn't see enough demand for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants