Reputation: 31
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
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
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
Reputation: 881
You can use @Expose
annotation for your fields with serialize
and deserialize
parameters to false
Upvotes: 0