Users Pricing

forum

Home Forums Do null properties of Java objects use memory? – MindStick

Do null properties of Java objects use memory?

Anonymous User 1990 20 Jul 2015
I am connecting to a webservice that sends down many different JSON objects. Rather than use a Java JSONObject I plan to use the GSON library to convert to POJOs. Rather than a huge amount of classes (one for each of the possible JSON service responses), I want to have a generic java object that can hold all possibilities:

public class GenericJSONResponse{
    public long objectKey;
    public GenericJSONResponse subObject1;
    public String description;
    // ...
}
I think this is a good aproach since the properties that get sent down by the server vary greatly. All server responses will only include a subset of the possible GenericJSONResponse properties. Will the properties that do not get populated take up memory even if they are null? My generic object will have many properties that are not used and I don't want them taking up precious memory.

1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md