0

I have been using JSON.net with CamelCasePropertyNamesContractResolver in an MVC project to return JSON. I have been using JSON.net 4.5 for a while and after updating it to version 9 the returning JSON format is different

example : in 4.5 a property call ALResults would return as aLResults int 9 the same property will come out as alResults

I can add attributes to each class and force the JSON to the format I need but is there a better way to do this?

Buzzzzzzz
  • 1,074
  • 13
  • 17
  • 2
    Newtonsoft intentionally changed the logic of it's `ToCamelCase()` as documented in [CamelCase Conversion format got changed from 6.0 to 9.0 #1427](https://github.com/JamesNK/Newtonsoft.Json/issues/1427). As JamesNK explains there, *You can get the old behavior by inheriting from DefaultContractResolver, override the method for resolving the property name with the ToCamelCaseV6 method. Then use your new DefaultContractResolver instead of the CamelCaseContractResolver.*. – dbc Sep 22 '17 at 00:16
  • 1
    The change was probably in [8.0.3](https://github.com/JamesNK/Newtonsoft.Json/releases/tag/8.0.3): *Fix - Fixed converting some property names to camel case*. – dbc Sep 22 '17 at 00:18

1 Answers1

0

Thanks to all the comments. Finally ended up updating the version and using JsonProperty in model classes
ex :

[JsonProperty("aLResults")]
public string ALResults{ get; set; }

in all JSON returns.
In the future, decided to use all simple in JSON returns.

Buzzzzzzz
  • 1,074
  • 13
  • 17