Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gson "toJson" on annonymus objects returns null

Tags:

java

android

I wanted to make an anonymous object to String using Gson.

my object is not null, but yet the method "toJson" return null.

enter image description here

How can i fix this?

like image 968
Elad Benda Avatar asked Dec 01 '25 10:12

Elad Benda


1 Answers

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.

like image 142
Timuçin Avatar answered Dec 03 '25 22:12

Timuçin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!