toJson() fails when trying to serialize an object of DoublyLinkedList<Record>
See original GitHub issueI have a DoublyLinkedList<Record>
object I want to jsonify with Gson, but when doing so I get this common infinite loop error even when I have done everything by the books:
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.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.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)
Record.java
class Record {
private String objectName;
private Object object;
Record(String objectName, Object object) {
this.objectName = objectName;
this.object = object;
}
Object getObject() {
return object;
}
String getObjectName() {
return objectName;
}
}
Gson Deserializing:
Type classType = new TypeToken<DoublyLinkedList<Record>>() {}.getType();
DoublyLinkedList<Record> linkedList = new Gson().fromJson(json, classType);
Gson Serializing:
Type classType = new TypeToken<DoublyLinkedList<Record>>() {}.getType();
String json = gson.toJson(list,classType);
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Unable to serialize Object to Json using Jackson
I tried this post, but it didn't help. Here is the class I'm trying to serialize: public class Repository { public String name; ......
Read more >How to Fix 'Cannot serialize object because no ... - YouTube
RestAssured #Automation #Error #message #IllegalStateException #JSON #serializer #classpath #Jackson #Databind #Gson #Johnzon #Yasson ...
Read more >Efficient JSON serialization with Jackson and Java
The serialization document, of course, can be stored, retrieved, shared, and archived. A preferred format was, once upon a time, XML; in recent ......
Read more >Serialization Error Handling - Json.NET
The error event is raised whenever an exception is thrown while serializing or deserializing JSON. Like all settings found on JsonSerializer, it can...
Read more >Migrate from Newtonsoft.Json to System.Text.Json - .NET
The System.Text.Json namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON). The System.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can’t tell if you have a really deeply nested tree or a cyclic reference (or both). Can you provide an executable sample that demonstrates the problem?
@JakeWharton Yes. Thank you for your time.