forked from alibaba/fastjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo2.java
More file actions
42 lines (32 loc) · 1.33 KB
/
Copy pathDemo2.java
File metadata and controls
42 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.alibaba.json.demo;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
public class Demo2 extends TestCase {
public void test_0() throws Exception {
Department dep = new Department();
dep.setId(123);
dep.setName("一级部门");
dep.setParent(dep);
String text = JSON.toJSONString(dep);
System.out.println(text);
JSON.parseObject(text, Department.class);
}
public static class Department {
private int id;
private String name;
private Department parent;
private transient List<Department> children = new ArrayList<Department>();
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@JSONField(serialize=false)
public Department getParent() { return parent; }
public void setParent(Department parent) { this.parent = parent; }
public List<Department> getChildren() { return children; }
public void setChildren(List<Department> children) { this.children = children; }
}
}