diff --git a/faroe/json/src/main/java/org/n52/faroe/json/JsonSettingsEncoder.java b/faroe/json/src/main/java/org/n52/faroe/json/JsonSettingsEncoder.java index 0c0083c0a..0600b4d95 100644 --- a/faroe/json/src/main/java/org/n52/faroe/json/JsonSettingsEncoder.java +++ b/faroe/json/src/main/java/org/n52/faroe/json/JsonSettingsEncoder.java @@ -18,6 +18,7 @@ import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.toSet; +import java.util.Comparator; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; @@ -46,6 +47,8 @@ public class JsonSettingsEncoder { private final JsonNodeFactory nodeFactory = Json.nodeFactory(); + private final Comparator, SettingValue>> comparator = + new SettingDefinitionComparator(); public Map>> sortByGroup(Set> defs) { return defs.stream().collect(groupingBy(SettingDefinition::getGroup, toSet())); @@ -161,11 +164,21 @@ private void encodeValue(ObjectNode o, Entry, SettingValue< public JsonNode encodeValues(Map, SettingValue> settings) { return settings.entrySet().stream() - .sorted(Entry.comparingByKey()) + .sorted(comparator) .collect(nodeFactory::objectNode, this::encodeValue, ObjectNode::setAll); } private TextNode textNode(Object value) { return nodeFactory.textNode(String.valueOf(value)); } + + private static class SettingDefinitionComparator implements Comparator, SettingValue>> { + + @Override + public int compare(Entry, SettingValue> o1, + Entry, SettingValue> o2) { + return o1.getKey().getKey().compareTo(o2.getKey().getKey()); + } + + } }