public class OuterClass implements Serializable {
int id;
ArrayList<InnerClass> listofInner;
public int getId() {
return id;
}
public void setId(int num) {
this.id = num;
}
public ArrayList<InnerClass> getListofInner() {
return listofInner;
}
public void setListofInner(ArrayList<InnerClass> list) {
this.listofInner = list;
}
public static class InnerClass implements Serializable {
String streetno;
private List<InnerClass> children = new ArrayList<InnerClass>();
public void setStreetno(String streetno) {
this.streetno = streetno;
}
public String getStreetno() {
return streetno;
}
public List<InnerClass> getChildren() {
return children;
}
public void setChildren(List<InnerClass> children) {
this.children = children;
}
}
}
OuterClass us = new OuterClass();
us.setId(111);
//Inner
OuterClass.InnerClass ic = new OuterClass.InnerClass();
ic.setStreetno("My Street");
ic.getChildren().add(new OuterClass.InnerClass());
ArrayList<OuterClass.InnerClass> ar = new ArrayList<OuterClass.InnerClass>();
ar.add(ic);
us.setListofInner(ar);
//DF
Encoder<OuterClass> outerClassEncoder = Encoders.bean(OuterClass.class);
Dataset<OuterClass> ds = spark.createDataset(Collections.singletonList(us), outerClassEncoder);
在上面 InnerClass 类中有属性 List children = new ArrayList();这是一种 InnerClass 列表。因此,当我尝试将此自定义对象转换为数据集时。我收到错误
java.lang.StackOverflowError:null at sun.reflect.generics.reflectiveObjects.TypeVariableImpl.equals(TypeVariableImpl.java:189)。
如果我从InnerClass中删除 children 属性。它工作正常。
所以任何人请帮助我.. :)