I want to compare whether the keys of two Gson converted objects are the same.
Example: I have one JSON object in a file customer.json which is stored locally:
{
name:"John",
age:25
}
There is an API which gives the same JSON data from a custom volley request which I am converting to a Customer
POJO.
Now I want to determine whether the JSON data stored locally and the JSON data received from the API are the same.
I am reading the JSON file and converting it to a Customer
as follows:
InputStream is = getContext().getResources().openRawResource(
R.raw.customerjson);
Gson gson = new Gson();
Reader reader = null;
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
Customer customerLocal = gson.fromJson(reader, Customer.class);
Now I have both of the converted Customer
objects (customerLocal
and customerServer
).
Everything is working fine; the problem is that I don't know how to compare the two Gson converted objects. Note that I want to compare only the keys (i.e. the variable name in the POJO, not the value).
Any help is greatly appreciated.