我有一个 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?任何示例代码都会在这里有所帮助。