私は木を表し、このクラスを持っている...ツリー構造
import java.util.Iterator; import java.util.LinkedList; import java.util.List; public class Leitur<T> implements Iterable<Leitur<T>> { T data; Leitur<T> parent; List<Leitur<T>> children; public Leitur(T data) { this.data = data; this.children = new LinkedList<Leitur<T>>(); } public Leitur<T> addChild(T child) { Leitur<T> childNode = new Leitur<T>(child); childNode.parent = this; this.children.add(childNode); return childNode; } @Override public Iterator<Leitur<T>> iterator() { return null; } }
...
Leitur<String> root = new Leitur<String>("aaa"); Leitur<String> node0 = root.addChild("node0"); Leitur<String> node00 = node0.addChild("node00"); Leitur<String> node000 = node00.addChild(null); Leitur<String> node1 = root.addChild("node1"); Leitur<String> node10 = node1.addChild("node10"); Leitur<String> node100 = node10.addChild(null); String text = new Gson().toJson(root);
問題はGsonが期待されるテキストを生成することができないということです。 whayを形作ることはできません。任意のアイデアwhay?
AndroidRuntime: FATAL EXCEPTION: main Process: pt.sys.opencvdemo, PID: 13475 java.lang.StackOverflowError: stack size 8MB at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401) at com.google.gson.stream.JsonWriter.beginArray(JsonWriter.java:287) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:95) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61) at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:976) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)