ObjectMapper icon indicating copy to clipboard operation
ObjectMapper copied to clipboard

Feature: Deterministic printing

Open bes opened this issue 5 years ago • 1 comments

I would like to propose a feature that would help a lot when debugging using printing to log.

For a given Mappable, it would be nice if the toJSONString(prettyPrint: true) could get a new property deterministic: Bool, that way every time you print a Mappable you can be confident that all properties are printed in the same order.

The easiest way would just be to sort the keys alphabetically, for every Mappable and sub Mappable.

Thank you for considering my feature request.

bes avatar Aug 21 '19 08:08 bes

It can be done easily, just enable this option to outside: https://developer.apple.com/documentation/foundation/jsonserialization/writingoptions/2888322-sortedkeys

I had to change the ObjecMapper source code to enable this option because hashing a json would never return the same value.

SerggioC avatar Jul 11 '20 19:07 SerggioC