Reputation: 263
Will comparing two objects of the same class by converting both of them into json strings / serialize them into bytes always work? Is it a good practice to do so?
Upvotes: 0
Views: 668
Reputation: 169498
No, this is probably not a good idea. What makes objects "equal" depends on the object. Comparing every field for equality may not be the correct test.
Further, the ordering of fields in JSON is not guaranteed, and I am not sure if the order of fields in the binary serialization format are guaranteed either. The serializer deciding in some cases to emit the fields in a different order could result in false negatives.
Upvotes: 4