Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Serialization to JSON is not deterministic #257

Closed
Halling69 opened this issue Feb 27, 2024 · 2 comments
Closed

Serialization to JSON is not deterministic #257

Halling69 opened this issue Feb 27, 2024 · 2 comments

Comments

@Halling69
Copy link

Description

Using .git as repository for a structurizr lite project even the smallest changes reshuffles the content of workspace.json making the git history unusable

My best guess is that this could be mitigated by using the objectmapper setting objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) in the AbstractJsonWriteClass
See: https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-annotations/latest/com/fasterxml/jackson/annotation/JsonPropertyOrder.html

Priority

I'm willing to add this feature myself and raise a PR (please confirm approach first)

More information

No response

@simonbrowndotje simonbrowndotje transferred this issue from structurizr/lite Feb 27, 2024
@simonbrowndotje
Copy link
Contributor

Thanks ... this helps, but doesn't solve the bigger problem, which is that the many of the JSON lists get mapped to Java sets (mostly LinkedHashSet) and the ordering of items is not guaranteed. I need to switch all of the LinkedHashSet references to TreeSet, and then ensure that everything being added to them implements Comparable. I did a quick test of this recently, repeatedly going to/from JSON several hundred times, and I did see the same JSON each time. It does potentially require a few other code changes too. This has been on my todo list for a while now, so leave it with me. 👍

@Halling69
Copy link
Author

Thanks - that would be wonderfull for my git history, looking forward to it 👏

@simonbrowndotje simonbrowndotje changed the title use MapperFeature.SORT_PROPERTIES_ALPHABETICALLY flag when writing workspace.json Serialization to JSON is not deterministic Mar 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants