简体   繁体   中英

How to compare / diff two objects in java

I have two object, one Object A is from the existing production, and another Object B is from our new pipeline. Eventually they both will be serialized into JOSN. Now, I want to compare if these two pipeline generate the same results, which means that if these two object/JSON carry the same set of data.

NOTE THAT, the same means, they have the same schema, and carry the same SET of data. For example,

Object A has

{"person" : [{"name": "alice"}, {"name": "bob"}, {"name" : "mike"}]}, 

and

Object B has

{"person" : [{"name": "bob"}, {"name": "alice"}, {"name" : "mike"}]}. 

This will cause difference if you run JSONDiss something, but in my case, they should be considered as same even if the sequence of key/value pair is difference. The structure of the Object/JSON could be more complex but the idea is that, in each bag/sub-bags, they should contains same set of data.

For my case, the goal is not just find if they are "same" or not, but find what is the difference? for example, Object 3 has a key/value pair called "name" : "Tom" that object 1 does not have. I always and only need to compare two objects.

I am wondering that is there any existing library for doing that ? or is there any suggestion for doing that ?

I know this is a bit old ... (saw this after)

Here is an answer that should work: Compare JSON with nested arrays and jsons (Array order does not matter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM