Suppose, we have a User
JSON
response:
{
"name": "Jack",
"age": 28,
"address": "Some address",
"occupation": "Employee",
"gender":"male"
}
With some network calls, we got another JSON
response:
{ "age":"27", "address":"Some new address" }
Now, the requirement is to update the existing object with the updated fields. For e.g:
{
"name": "Jack",
"age":"27",
"address":"Some new address",
"occupation": "Employee",
"gender":"male"
}
Notice that age
and address
was changed. This can be done by making null
checks for small user object but doesn't look smart enough for some object like Product
that will have more than 100 fields.
Looking for an efficient way to do it in Java
/Kotlin
.