Skip to content
Advertisement

Gson showing nested Object as null

Im trying to deserialize objects into JSON, one object contains a nested object. I created an instance of both the nested object (UserAddress)and the one containing it (UserObjectWithNestedObject). However, when I serialize, the nested object is null. So I ran the program in debugger mode to see when it goes null.

It seems to be null when I use it as a field when instantiating the UserObjectWithNestedObject class but I dont know why because I instantiated in the objects in the same scope so you’d think the they would be able to communicate with no issue

enter image description here Sorry, you might need to zoom

My classes

Main

JavaScript

UserObjectWithNestedObject

JavaScript

UserAddress (this is the nested object that turns null)

JavaScript

Advertisement

Answer

You did not initialize it 🙂

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement