开发者

Computing JSON diffs

Considering two JSON objects, how to compute the difference (subset) between them in Java ? I am currently using the net.sf.json lib;

I would be particularly interested in having a report like: JSON1 has these items 开发者_JS百科that JSON2 does not have; Is there something built-in ?


It appears from the tag that you are intending to use Java for this task.

What you can do is, have the JSON string parsed into Java domain objects, such as Student, Bus, Animal, or whatever your domain is, then overriding the equals and hashcode methods in your domain.

For example,

class Animal{
 private String name;

 public boolean equals(Object object){
  ...
 }

 public int hashcode(){
  ...
  // better to use Apache commons hashcodebuilder for this purpose
 }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜