0
Java 객체와 Jackson을 사용하여이 json 콘텐트를 재귀 적으로 만들려면 어떻게해야합니까? :json에서 java 객체를 만드는 방법
{
"children": [
{
"children": [
{
"name": "cluster",
"children": [
{
"name": "AgglomerativeCluster",
"size": 3938
},
{
"name": "TestCLuster",
"size": 3938
}
]
}
],
"name": "analytics"
}
],
"name": "flare"
}
가 여기 내 객체 구조는 지금까지이며, DendogramVO라는 이름의 부모와라는 이름의 자식 클래스에는 어린 목록을 가지고 자녀 : 당신의 JSON 알 수없는 속성이 포함
import java.util.List;
public class DendogramVO {
private List<Children> children;
private String name;
public List<Children> getChildren() {
return this.children;
}
public void setChildren(List<Children> children) {
this.children = children;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
import java.util.List;
public class Children {
private List<Children> children;
private String name;
public List<Children> getChildren() {
return children;
}
public void setChildren(List<Children> children) {
this.children = children;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
어린이 #의 toString를 (그들에 걸쳐 올 때 실패 (또는 클래스에 추가)하지 않도록
ObjectMapper
를 구성해야 내가 게시 한 트리 구조? –@ user470184 예. 가장 많이 중첩 된 json 객체는 두 개의 json 객체를 포함하는 json 배열을 포함합니다. 이름은'cluster'입니다. 그것을 포함하는 객체는'analytics'라는 이름을 가지고 있습니다. 그리고 그 물체는 '아이들'입니다. 위의 코드에서'children.getName()'을 실행하면 루트 json 객체의 이름 인'flare'가 출력됩니다. –
코드를 사용해 보았습니다. mapper.configure (DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 컴파일러 오류가 발생합니다. ObjectMapper 유형의 메서드 configure (SerializationConfig.Feature, boolean)가 인수 (DeserializationFeature, boolean)에 적용되지 않습니다. " –