在Java中反序列化JSON的最快方法是什么 [英] What is the fastest way to deserialize JSON in java

查看:125
本文介绍了在Java中反序列化JSON的最快方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在JAVA中解析json的最快方法是什么?

I'm wondering what is the fastest way to parse json in JAVA ?

  • 使用Array中内置的库和Object对象获取默认的对象图
  • 使用您自己的java bean获取自定义对象图

谢谢

推荐答案

将解析的JSON映射到Java bean涉及其他步骤,因此使用原始接口(例如Jackson的流API)会更快.这样,您也可以阅读直到拥有所需的内容并停止解析.

Mapping parsed JSON to Java bean involves additional steps, so using the raw interface (e.g. the streaming API of Jackson) will be faster. This way, you can also read until have what you need and stop parsing.

响应@sikorski
来自杰克逊Wiki :

In response to @sikorski
From Jackson Wiki:

数据绑定是使用Streaming API作为底层JSON构建的 读/写系统:因此,它具有高性能[...],但具有 与纯流式传输/增量式相比,有些额外的开销 处理

Data binding is built using Streaming API as the underlying JSON reading/writing system: as such it has high-performance [...], but has some additional overhead compared to pure streaming/incremental processing

这几乎是不可避免的.如果要编写通用的Jackson解析器,则显然不能在其中使用自定义类型.因此,在使用通用解析器读取JSON之后,您必须构造自定义类型,因此通用解析器将更快.值得注意的是,这样的开销很小,几乎不需要优化.

This is pretty much inevitable. If you are writing a generic Jackson parser, you obviously can't use custom types in it. Therefore it follows that you'll have to construct the custom type after you read the JSON with the generic parser, and hence the generic parser will be faster. It's worth noting though that such overhead is very small and almost never something you need to optimize away.

这篇关于在Java中反序列化JSON的最快方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆