gpt4 book ai didi

java - 为此用例选择最高效的 JSON 库

转载 作者:行者123 更新时间:2023-12-01 19:03:06 25 4
gpt4 key购买 nike

我有一个 JSF 网格类型组件,其中每个单元格都可以单独编辑,并且每个单元格的数据包含在名为 DataObject(DO) 的 POJO 中。 DO的结构是这样的:

public class DO {

//Id should be the coordinate. eg x@y . x is the row position and y is the column position
private String id;
//This is value that goes to the client after applying formatter
private Object value;
//flag to indicate whether the cell will be disabled
private boolean disabled;
//flag to indicate whether the cell will be rendered
private boolean rendered=true;
//Editor type for the cell
private String editorType;

}

所以基本上 id 字段标识网格中的单元格位置(行和列)。

现在,在我们的例子中,我们可以有一个 1000 行 X 100 列的网格,其中网格本身最初填充稀疏,这意味着大多数单元格最初不包含任何 DO。因此,大约 30% 的单元格将包含数据,其余的将不包含任何数据。我需要通过ajax将JSON格式的数据从服务器传递到客户端javascript。这个想法是迭代 DO 的集合并构造 JSON String 。

因此,包含两个单元格数据的网格的 JSON 看起来像这样:

{
id1 : {
editorType:'InputEditor',
value:'1234123',
disabled:'false',
rendered:'true'
},

id2 : {
editorType:'SomeCustomEditor',
value:'23456',
disabled:'true',
rendered:'true'
}
}

我可以在这里使用哪些现有的 JSON Java 库以最有效的方式生成此输出 JSON?任何示例代码都会有帮助。

最佳答案

我已经测试了许多(发送/发送)JSON 解析器以实现非常高速的消息传递过程,应用程序必须每秒发送 200*100 条消息。由于 UI 是 JavaScript(和 websocket)——我们决定使用 JSON。我们从 JSONObject 开始——但它惨遭失败。

我脑子里没有数字,但这里是这些 API 的相对速度:
(最快)Jackson > Gson >>> JSONObject (最慢)

  1. Jackson
  2. Gson
  3. JSONObject

我们计划评估json-smart ,但与 jackson 一起得到了不错的表现——所以停止了。如果您正在关注它并计划运行基准测试。一定要包括这个。我们观察到的唯一问题是,这似乎不太受欢迎,因此我们犹豫是否使用它,以避免出现没有人倾听的极端情况失败。

关于java - 为此用例选择最高效的 JSON 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11434028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com