我想使用Jackson将这样的对象序列化为Json String。有可能吗?
public class Simple {
public static void main(String[] args) {
List<Person> emptylist = new ArrayList<>();
Person p3 = new Person("grandpa", emptylist);
Person p2 = new Person("father", emptylist);
Person p1 = new Person("i am", emptylist);
p2.children.add(p3);
p1.children.add(p2);
}
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public static class Person {
String name;
List<Person> children;
}
}
您可以执行以下操作: