Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone.

I have a problem with convert the object to json. I'm using gson to convert the java object to json string, but i got an error for this. Below is the describe

I have a class Bus
Java
class Bus{
 private int id;
 private Route route;

  //setters and getters
}

class Route{
 private int id;
 private List<Bus> listBus;
 
 //setters and getters
}


When i using gson to convert the bus object to json,

Java
Gson gson = new Gson();
Bus bus = getABus();//get the bus
String json = gson.toJson(bus);


it generate this erros:
Java
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)


Could anyone know how to solve this problem please?

Thanks
Clark
Posted

1 solution

Looks like you need to write a custom serializer. Check out the guide: http://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserialization[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900