开发者

How to create a JSON string which only contains the changed values?

开发者 https://www.devze.com 2023-04-06 15:26 出处:网络
I want to minimize the amount of JSON data transferred. Let\'s say I have a class with 100 key/value pairs and then I change one of these and want to transfer that change, and nothing but that change,

I want to minimize the amount of JSON data transferred. Let's say I have a class with 100 key/value pairs and then I change one of these and want to transfer that change, and nothing but that change, not the 99 un开发者_如何转开发changed ones.

Is there a java lib for making such a patch or diff?


You have to compare the new values with the old values and then create the JSON. So a pseudocode is:

for each entry in old values
  find entry key in new values
  if new value != old value
    put this into list of modified entries
end for
convert modified entries to JSON

Really nothing complicated.

0

精彩评论

暂无评论...
验证码 换一张
取 消