我试图按照RFC6901又称JSON指针的规范,在Jersey中使用MOXy将递归bean编组为JSON。
例如,我想整理这个:
public class Bean {
public Integer id;
public String name;
public Bean other;
public List<Bean> next;
}
x = new Bean(123, "X");
a = new Bean(456, "A");
x.other = a;
x.next.add(x);
x.next.add(a);
进入这个:
{
"id": 123,
"name": "X",
"a": { "id": 456, "name": "A", "next": [ ] },
"next": [
{ "$ref": "#" },
{ "$ref": "#/a" }
]
}
然后将此JSON解组到原始bean。有人对此问题有任何建议/解决方案吗?