z0l39
z0l39

Reputation: 31

When working with GSON is it mandatory to have classes for JSON objects that are needed to be excluded?

I am trying to use GSON in order to parse a JSON that include some classes and fields that need to be excluded. Do I have to create classes for such objects, and include such fields in classes I create?

Upvotes: 0

Views: 232

Answers (3)

Martin Zeitler
Martin Zeitler

Reputation: 76679

Just don't add the field to the class and ignore it. There is no need to use all input, even with auto-mapping. Whatever has no @SerializedName annotation will not be mapped- @Expose also controls that. But the actual beauty of GSON is parsing such nested nodes to classes of various types.

just see: @SerializedName, @Expose.

Upvotes: 0

Intsab Haider
Intsab Haider

Reputation: 3561

As it take Class<object> classOfT as parameter so we have to pass parameter, but if you dont want to make your custom class you can use it by this way.

Gson gson = new Gson();
gson.fromJson("Response Json String", Object.class);

and you can play with that object in many ways.

Upvotes: 1

Agnaramon
Agnaramon

Reputation: 881

You can use @Expose annotation for your fields with serialize and deserializeparameters to false

Upvotes: 0

Related Questions