I would like to be able to generate an MD5 checksum of any Java POJO across JVMs. The approach would be to serialize the object to JSON then MD5 the JSON.
The issue is JSON serialization with Jackson is not deterministic mainly because many collections are not deterministic.
ObjectMapper mapper = new ObjectMapper()
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
... // all other custom modules / features
;
These two features solve two of the problems of keeping fields sorted on POJOs as well as Maps.
The next challenge is to modify any collection on the fly and sort it. This requires every element in every collection to be sortable but let's assume that is ok for now.
Is there a way to intercept every collection and sort it before it is serialized?