I wanted to make an anonymous object to String using Gson.
my object is not null, but yet the method "toJson" return null.

How can i fix this?
From the users guide:
Gson can also deserialize static nested classes. However, Gson can not automatically deserialize the pure inner classes since their no-args constructor also need a reference to the containing Object which is not available at the time of deserialization.
Gson doesn't do the serialisation and returns null. You can use a static nested class instead of a anonymous inner class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With