2012-03-13 38 views
8

我刚刚将Json.NET从3.5版本7升级到4.0版本8,并意识到seralization不是以相同的方式完成的。在序列化包含标准字典的对象时,3.5版本会保留字典密钥不变,但使用4.0时,合约解析器也适用于密钥。CamelCase在Json.NET版本4中发生了重大变化

例如,使用以下JsonSerializerSettings时:

jsonSerializerSettings = new JsonSerializerSettings 
{ 
    Converters = new List<JsonConverter> { new JavaScriptDateTimeConverter() }, 
    NullValueHandling = NullValueHandling.Ignore, 
    ReferenceLoopHandling = ReferenceLoopHandling.Ignore, 
    ContractResolver = new CamelCasePropertyNamesContractResolver() 
}; 

和序列化的对象时像这样的:在Attributes字典

[JsonObject(MemberSerialization.OptOut)] 
public class ProductFilter 
{ 
    public int Id { get; set; } 
    public int NodeId { get; set; } 
    public IDictionary<string, ProductFilterAttribute> Attributes { get; set; } 
} 

键变得驼峰为好。在版本3.5R7中保持不变,我认为这是正确的方法。

实施例从3.5R7输出片段:

{ 
    "id": 98659, 
    "nodeId": 317970, 
    "attributes": { 
     "FULL_TIME_USE": { 
      values: [ { "1" } ], 
      formattedValue: "... 

实施例从4.0R8输出片段:

{ 
    "id": 98659, 
    "nodeId": 317970, 
    "attributes": { 
     "fULL_TIME_USE": { 
      values: [ { "1" } ], 
      formattedValue: "... 

(我们有大量的类似的代码,所以除去驼峰解决和添加[JsonProperty("id")][JsonProperty("nodeId")]等是不是真的在这里)

任何想法如何解决这个问题?

回答

1

严......降级为符合您需要的版本。

然后用Json.NET提交错误报告。

2

嗯 - 发现这个变化是在4.0R1和4.0R2之间完成的。 Here's the issue.

从json的角度我可以看到它是正确的,但我不确定是否真的同意实际的更改。至少不要在两个小版本之间做出这样的改变。

解决方法也发布在那里。

相关问题