Json.NET Updates: Merge, Dependency Injection, F# and JSONPath Support

Json.NET 6.0 收获了今年的四个发布版本,包括 F# 特定功能、JSON 路径查询支持、依赖注入框架集成、JSON 对象合并能力等新特性。此版本还引入了 JSON 合并功能,允许将 JSON 对象或数组合并到另一个对象中,同时支持 LINQ 到 JSON。此外,还增加了与依赖注入的整合、F# 特定功能如支持分化联合类型、F# 集合、列表、序列、集合和映射,并支持元数据属性和 JSON 路径查询等功能。

Json.NET 6.0 received 4 releases this year, the latest last week. Over these releases, several new features have been added, including several F# specific features, support for JSONPath querying, ability to integrate with Dependency Injection frameworks, ability to Merge JSON objects and more.

Serializers shipped with the .NET framework, the Data Contract JSON Serializer and theJavaScriptSerializer, leave room for improvement both on features and performance front. Json.NET fills this gap and is already a popular open-source alternative within the .NET community. It comes with several features such as LINQ-to-JSON, BSON support, support foranonymous types, support for popular ORMs (EF and NHiberate) and more, not present in the built-in counterparts. This, combined with better performance. (see the feature comparison and detailed benchmarks)

Some important features introduced this year that make Json.NET even better -

  • JSON Merge - allows you to merge a JSON object or an array into another.

    This is similar to the jQuery's extend method, but is also recursive and gives more options in handling arrays - when merging arrays (including those nested within objects), you can specify whether they should be concatenated together, unioned, merged by position, or completely replaced.

    Merge also works with LINQ-to-JSON. Have a look at the tests to understand this feature better and the various use cases it supports.
  • Integration with Dependency Injection - you can now deserialize interfaces or abstract types directly if you specify a mechanism to resolve such a type at runtime, such as using a dependency injection framework like Autofac or Ninject. All you have to do is inherit from the DefaultContractResolver, and use your own resolver in the serializer.
  • Several F# specific features - support for discriminated unions, F# collections, F# lists, sequences, sets and maps. For new immutable collections, if collection of T has a constructor that takes IEnumerable<T> then Json.NET will automatically work when deserializing to that collection.
  • Ability to handle metadata properties, without having to guarantee JSON object property order. Json.NET uses metadata for some features such as preserving types or references and requires the metadata to be ordered before other properties for these features to work fine. A setting called MetadataPropertyHandling.ReadAhead can be set to enable this, at a slight cost of increased memory usage and lesser speed. 
  • Full support for JSONPath querying. Similar to XPath, this is useful for navigating JSON data and can be useful if you only need specific values without necessarily deserializing the entire JSON object.

Other interesting features are ability to deserialize nested DataTables as well as arrays within DataTables, support for single-line comments within JSON, support for Windows Phone 8.1 and more. Refer to posts from James Newton-King for more details.

Another interesting and performant third-party alternative for serialization in .NET isServiceStack.Text (now commercial open source).

转载于:https://www.cnblogs.com/rongfengliang/p/3923118.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值