-
-
Notifications
You must be signed in to change notification settings - Fork 57
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 both camel case and non camel case parameters #31
Comments
Hi, You can tweak the way PriceDiscountType is serialized with Newtonsoft.Json, JsonSubtypes match serialization of |
@manuc66 Thank you for such an awesome library! I had similar issue with case of property names. Here is my current working setup:
As @camhart I have "Type" property in C# class, and firstly used Could you please explicilty state in documentation that we should use JSON object property name, not the class one? Is it possible to make you converter be aware of JsonSerializer settings to use C# class property name? |
Hi @Hauptsatana, @camhart I had read a bit too rapidly the original question (sorry), I thought it was about about the case of the enum. So here is what I thought about... : [JsonConverter(typeof(StringEnumConverter), true)]
public enum PriceDiscountType
{
A,
B
} -- [JsonConverter(typeof(JsonSubtypes), "kind")]
public interface IAnimal
{
[JsonProperty("kind")]
string Type { get; }
}
public class Dog : IAnimal
{
public string Type { get; } = "Dog";
public string Breed { get; set; }
}
[Test]
public void Demo()
{
var animal =
JsonConvert.DeserializeObject<IAnimal>(
"{\"kind\":\"Dog\",\"Breed\":\"Jack Russell Terrier\"}");
Assert.AreEqual("Jack Russell Terrier", (animal as Dog)?.Breed);
Assert.AreEqual("Dog", animal.Type);
} As for now there is no know workaround to match For the documentation concern, as a consumer of this library, where in the documentation would you have expected to find this ? (And feel free to submit a PR ;-)) |
Support for different case is released with v1.4.0 and documentation has been updated |
Is this enabled by default? Or is there some magic way to turn it on? Thanks btw! Edit: Looks like I just need to explicitly set the JsonProperty value. Is that correct? |
@camhart It's enabled by default and
|
Here's my current setup:
However, at times the default serialization is to use camel case. Is there a way to make this work for both camel case, and non camel case, so that I don't have to worry about which is being used?
The text was updated successfully, but these errors were encountered: