开发者

please give a clue about writing json object comparision at java side

I am planning to compare two json objects at java side. each service json object structure may vary. So, I want to write common code for json object comparision. I cant use Jackson or any other library/API. because, I need to get approval to use. It will be more burden rather than writing my own java coding. So, Please give idea. How can i write json object comparision? And, Please provide sample code base Thanks in advanc开发者_StackOverflowe


Take a look at the reference implementation and extract the parts you need.


I'm assuming that you are starting from some proprietary or in-house classes for representing JSON in memory, and that the representation is based on hash tables / hash maps or some such.

The way to do the comparison is to recursively copy the name-value pairs from the JSON object trees into a tree built using TreeMaps. Then you can recursively walk / iterate the tree of TreeMaps of the two versions of the JSON.

Alternatively extract the attribute names into TreeSets, iterate those to give you the attribute names in a consistent order.

Please provide sample code base

I've written stuff like this myself. IIRC, it is in the unit tests for one of my GPL'ed projects. Ooops!! Sorry :-)


FWIW - you should be telling / reminding your management how much extra work their Open Source usage policies are making for you ... and adjusting your project estimates to take this into account.

FWIW 2 - grabbing sample code from some random person on the net is more risky (from an IP perspective) than using a published open source library. At least with the library, you know where it comes from and what license conditions apply. (Someone could send you proprietary code stolen from your favourite software monopolist. I bet your lawyers would just LOVE that!)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜