I just upgraded Json.NET from version 3.5 Release 7 to 4.0 Release 8 and realized that serialization is not doing the same. When serializing an object that contains the standard dictionary version 3.5, the dictionary keys remained unchanged, but when using 4.0, the contract recognizer is also applied to the keys.
For example, using the following JsonSerializerSettings:
jsonSerializerSettings = new JsonSerializerSettings { Converters = new List<JsonConverter> { new JavaScriptDateTimeConverter() }, NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver() };
and when serializing an object like this:
[JsonObject(MemberSerialization.OptOut)] public class ProductFilter { public int Id { get; set; } public int NodeId { get; set; } public IDictionary<string, ProductFilterAttribute> Attributes { get; set; } }
keys in the Attributes dictionary also become camelCase. In version 3.5R7, those that remain unchanged, and I think the right way.
An example of a fragment from output 3.5R7:
{ "id": 98659, "nodeId": 317970, "attributes": { "FULL_TIME_USE": { values: [ { "1" } ], formattedValue: "...
Sample snippet from 4.0R8 output:
{ "id": 98659, "nodeId": 317970, "attributes": { "FULL_TIME_USE": { values: [ { "1" } ], formattedValue: "...
(We have a lot of similar code, so removing the camelCase solution and adding [JsonProperty("id")] , [JsonProperty("nodeId")] , etc. is not an option here)
Any ideas on how to solve this?