structurizr / java

Structurizr for Java

Home Page:https://docs.structurizr.com/java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serialization to JSON is not deterministic

Halling69 opened this issue · comments

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

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. 👍

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