Java 杰克逊 VS。格森
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2378402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hymanson Vs. Gson
提问by Suraj Chandran
After searching through some existing libraries for JSON, I have finally ended up with these two:
在搜索了一些现有的 JSON 库之后,我终于得到了这两个:
- Hymanson
- Google GSon
- Hyman逊
- 谷歌GS
I am a bit partial towards GSON, but word on the net is that GSon suffers from a certain celestial performance issue(as of Sept 2009).
我有点偏向 GSON,但网上有消息称 GSon 存在某种天体性能问题(截至 2009 年 9 月)。
I am continuing my comparison; in the meantime, I'm looking for help to make up my mind.
我继续我的比较;与此同时,我正在寻求帮助来下定决心。
采纳答案by mickthompson
I did this research the last week and I ended up with the same 2 libraries. As I'm using Spring 3 (that adopts Hymanson in its default Json view 'HymansonJsonView') it was more natural for me to do the same. The 2 lib are pretty much the same... at the end they simply map to a json file! :)
我上周做了这项研究,最终得到了相同的 2 个库。由于我使用的是 Spring 3(在其默认的 Json 视图“ HymansonJsonView”中采用 Hymanson ),因此我也更自然地这样做。2个lib几乎相同......最后它们只是映射到一个json文件!:)
Anyway as you said Hymansonhas a + in performance and that's very important for me. The project is also quite active as you can see from their web pageand that's a very good sign as well.
不管怎样,正如你所说的,Hyman逊在表现上有 +,这对我来说非常重要。正如您从他们的网页上看到的那样,该项目也非常活跃,这也是一个非常好的迹象。
回答by StaxMan
Hymanson and Gson are the most complete Java JSON packages regarding actual data binding support; many other packages only provide primitive Map/List (or equivalent tree model) binding. Both have complete support for generic types, as well, as enough configurability for many common use cases.
Hymanson 和 Gson 是关于实际数据绑定支持最完整的 Java JSON 包;许多其他包只提供原始地图/列表(或等效的树模型)绑定。两者都完全支持泛型类型,以及为许多常见用例提供足够的可配置性。
Since I am more familiar with Hymanson, here are some aspects where I think Hymanson has more complete support than Gson (apologies if I miss a Gson feature):
由于我对 Hymanson 更熟悉,因此我认为 Hymanson 比 Gson 有更完整的支持的一些方面(如果我错过了 Gson 功能,请道歉):
- Extensive annotation support; including full inheritance, and advanced "mix-in" annotations (associate annotations with a class for cases where you can not directly add them)
- Streaming (incremental) reading, writing, for ultra-high performance (or memory-limited) use cases; can mix with data binding (bind sub-trees) -- EDIT: latest versions of Gson also include streaming reader
- Tree model (DOM-like access); can convert between various models (tree <-> java object <-> stream)
- Can use any constructors (or static factory methods), not just default constructor
- Field and getter/setter access (earlier gson versions only used fields, this may have changed)
- Out-of-box JAX-RS support
- Interoperability: can also use JAXB annotations, has support/work-arounds for common packages (joda, ibatis, cglib), JVM languages (groovy, clojure, scala)
- Ability to force static (declared) type handling for output
- Support for deserializing polymorphic types (Hymanson 1.5) -- can serialize AND deserialize things like List correctly (with additional type information)
- Integrated support for binary content (base64 to/from JSON Strings)
- 广泛的注释支持;包括完全继承和高级“混合”注释(在无法直接添加注释的情况下,将注释与类相关联)
- 流式(增量)读取、写入,用于超高性能(或内存受限)用例;可以与数据绑定(绑定子树)混合使用——编辑:最新版本的 Gson 还包括流式阅读器
- 树模型(类似 DOM 的访问);可以在各种模型之间转换(树<-> java对象<->流)
- 可以使用任何构造函数(或静态工厂方法),而不仅仅是默认构造函数
- 字段和 getter/setter 访问(较早的 gson 版本仅使用字段,这可能已更改)
- 开箱即用的 JAX-RS 支持
- 互操作性:还可以使用 JAXB 注释,支持通用包(joda、ibatis、cglib)、JVM 语言(groovy、clojure、scala)
- 能够强制输出静态(声明)类型处理
- 支持反序列化多态类型(Hymanson 1.5)——可以正确地序列化和反序列化 List 之类的东西(带有附加类型信息)
- 对二进制内容的集成支持(base64 到/从 JSON 字符串)
回答by inder
Gson 1.6 now includes a low-level streaming API and a new parser which is actually faster than Hymanson.
Gson 1.6 现在包含一个低级流 API 和一个新的解析器,实际上比 Hymanson 更快。
回答by raymond.mh.ng
It seems that GSon don't support JAXB. By using JAXB annotated class to create or process the JSON message, I can share the same class to create the Restful Web Service interface by using spring MVC.
似乎 GSon 不支持 JAXB。通过使用JAXB注解类来创建或处理JSON消息,我可以共享同一个类来使用spring MVC创建Restful Web Service接口。
回答by snegi
Adding to other answers already given above. If case insensivity is of any importance to you, then use Hymanson. Gson does not support case insensitivity for key names, while Hymanson does.
添加到上面已经给出的其他答案。如果不区分大小写对您来说很重要,那么请使用 Hymanson。Gson 不支持键名不区分大小写,而 Hymanson 支持。
Here are two related links
这是两个相关的链接
(No) Case sensitivity support in Gson : GSON: How to get a case insensitive element from Json?
(否)Gson 中的区分大小写支持: GSON:如何从 Json 获取不区分大小写的元素?
Case sensitivity support in Hymanson https://gist.github.com/electrum/1260489
Hymanson 中的区分大小写支持 https://gist.github.com/electrum/1260489