1 package org.simantics.scl.data.xml;
3 import java.io.IOException;
5 import com.fasterxml.jackson.core.JsonProcessingException;
6 import com.fasterxml.jackson.databind.JsonNode;
7 import com.fasterxml.jackson.databind.ObjectMapper;
8 import com.fasterxml.jackson.databind.SerializationFeature;
10 public class JsonNodeHelper {
12 private static final ObjectMapper SORTED_MAPPER = new ObjectMapper();
15 SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
18 public static String toJsonString(JsonNode node) throws JsonProcessingException {
19 final Object obj = SORTED_MAPPER.treeToValue(node, Object.class);
20 final String json = SORTED_MAPPER.writeValueAsString(obj);
24 public static JsonNode fromJsonString(String s) throws JsonProcessingException, IOException {
25 return SORTED_MAPPER.readTree(s);