All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sdase.commons.shared.asyncapi.util.JsonNodeUtil Maven / Gradle / Ivy

Go to download

A libraries to bootstrap services easily that follow the patterns and specifications promoted by the SDA SE

There is a newer version: 7.0.88
Show newest version
package org.sdase.commons.shared.asyncapi.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.SortedMap;
import java.util.TreeMap;

public class JsonNodeUtil {

  private JsonNodeUtil() {
    // No constructor
  }

  public static void sortJsonNodeInPlace(JsonNode node) {
    if (!node.isMissingNode() && node.isObject()) {
      ObjectNode objectNode = (ObjectNode) node;
      SortedMap fields = new TreeMap<>();
      objectNode.fields().forEachRemaining(e -> fields.put(e.getKey(), e.getValue()));
      objectNode.removeAll();
      fields.forEach(objectNode::set);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy