Exception on toJson
See original GitHub issueI’m trying to generate a JSON from an object that represents an undirected Graph, but when I run the program it throws this Exception over and over again until the program stops
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:1018)
The weird thing is that it generates the JSON, the size is 57MB and I don’t know if that is normal or if is correct because is too big for reviewing it all.
This is the code that I use to create the JSON
Gson gson = new GsonBuilder().setPrettyPrinting().create(); File file = new File ("data/test.json"); if (!file.exists()) file.createNewFile(); FileWriter writer = new FileWriter(file); gson.toJson(graph,writer); writer.close();
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
A doubly-linked list seems like a pretty obvious place where a reference cycle would exist and cause infinite recursion. Did you register a custom type adapter for it?
On Sun, Nov 18, 2018, 11:04 AM JuanWTF <notifications@github.com wrote:
It doesn’t, this is my implementation, some variable names are in Spanish, but I think it is easy to understand, I use an adjacency list with a hashmap of LinkedList instead of an array because the number of vertexes can vary and I need to save information about the weight of the edges.
`public class Grafo <K extends Comparable <K>, V extends Vertice, A > implements IGrafo<K, V, A> { private int vertices;
}`