杰克逊VS。格森

发布于 2024-08-24 13:45:37 字数 1780 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

雾里花 2024-08-31 13:45:37

我上周做了这项研究,最终得到了两个相同的库。当我使用 Spring 3 (在其默认 Json 视图中采用 Jackson 'JacksonJsonView') 对我来说这样做更自然。这两个库几乎是相同的......最后它们只是映射到一个 json 文件! :)

不管怎样,正如你所说,杰克逊的表现有+,这对我来说非常重要。该项目也非常活跃,您可以从他们的网页中看到,这也是一个非常好的迹象。

I did this research the last week and I ended up with the same 2 libraries. As I'm using Spring 3 (that adopts Jackson in its default Json view 'JacksonJsonView') 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! :)

Anyway as you said Jackson has a + in performance and that's very important for me. The project is also quite active as you can see from their web page and that's a very good sign as well.

酒几许 2024-08-31 13:45:37

Jackson 和 Gson 是关于实际数据绑定支持的最完整的 Java JSON 包;许多其他包仅提供原始映射/列表(或等效的树模型)绑定。
两者都完全支持泛型类型,并且为许多常见用例提供了足够的可配置性。

由于我对 Jackson 比较熟悉,所以我认为 Jackson 在以下几个方面比 Gson 有更完整的支持(如果我错过了 Gson 功能,请原谅):

  • 广泛的注释支持;包括完全继承和高级“混合”注释(在无法直接添加注释的情况下将注释与类相关联)
  • 流式(增量)读取、写入,用于超高性能(或内存限制)用例;可以与数据绑定混合(绑定子树)--编辑:最新版本的 Gson 还包括流式读取器
  • 树模型(类似 DOM 的访问);可以在各种模型之间进行转换(树<->java对象<->流)
  • 可以使用任何构造函数(或静态工厂方法),而不仅仅是默认构造函数
  • 字段和getter / setter访问(早期的gson版本仅使用字段, 互
  • 开箱即用的 JAX-RS 支持
  • 支持/解决方法
  • 操作性:还可以使用 JAXB 注释,支持常见包(joda、ibatis、cglib)、JVM 语言(groovy、clojure、scala)的 强制输出的静态(声明)类型处理
  • 支持反序列化多态类型 (Jackson 1.5) - 可以正确序列化和反序列化 List 等内容(带有附加类型信息)
  • 对二进制内容的集成支持(base64 与 JSON 字符串之间的转换)

Jackson 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.

Since I am more familiar with Jackson, here are some aspects where I think Jackson has more complete support than Gson (apologies if I miss a Gson feature):

  • 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 (Jackson 1.5) -- can serialize AND deserialize things like List correctly (with additional type information)
  • Integrated support for binary content (base64 to/from JSON Strings)
一张白纸 2024-08-31 13:45:37

Gson 1.6 现在包含一个低级流 API 和一个新的解析器,实际上比 Jackson 更快。

Gson 1.6 now includes a low-level streaming API and a new parser which is actually faster than Jackson.

泛滥成性 2024-08-31 13:45:37

添加到上面已经给出的其他答案。如果不区分大小写对您来说很重要,那么请使用 Jackson。 Gson 不支持键名称不区分大小写,而 jackson 则支持。

这里有两个相关链接

(否)Gson 中的区分大小写支持:
GSON:如何从 Json 获取不区分大小写的元素?

杰克逊支持区分大小写
https://gist.github.com/electrum/1260489

Adding to other answers already given above. If case insensivity is of any importance to you, then use Jackson. Gson does not support case insensitivity for key names, while jackson does.

Here are two related links

(No) Case sensitivity support in Gson :
GSON: How to get a case insensitive element from Json?

Case sensitivity support in Jackson
https://gist.github.com/electrum/1260489

无畏 2024-08-31 13:45:37

看来GSon不支持JAXB。
通过使用 JAXB 带注释的类来创建或处理 JSON 消息,我可以共享同一个类来使用 Spring MVC 创建 Restful Web Service 接口。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文