Class JSONUtil

java.lang.Object
org.revapi.configuration.JSONUtil

public final class JSONUtil extends Object
A utility class for JSON files. The JSON specification doesn't allow comments but the extension's configuration is likely to contain comments so that users can "annotate" what individual configuration items mean.
Since:
0.1
Author:
Lukas Krejci
  • Method Details

    • convert

      public static com.fasterxml.jackson.databind.JsonNode convert(org.jboss.dmr.ModelNode node)
    • convert

      public static org.jboss.dmr.ModelNode convert(com.fasterxml.jackson.databind.JsonNode node)
    • parse

      public static com.fasterxml.jackson.databind.JsonNode parse(String string)
    • parse

      public static com.fasterxml.jackson.databind.JsonNode parse(Reader reader) throws IOException
      Throws:
      IOException
    • toString

      public static String toString(com.fasterxml.jackson.databind.JsonNode json)
    • isNullOrUndefined

      public static boolean isNullOrUndefined(@Nullable com.fasterxml.jackson.databind.JsonNode node)
    • stripComments

      @Deprecated public static InputStream stripComments(InputStream json, Charset charset)
      Deprecated.
      This ignores the charset and uses UTf-8. Use stripComments(InputStream) instead.
      Parameters:
      json - the JSON-encoded data
      charset - the charset of the data
      Returns:
      an input stream that strips comments from json data provided as an input stream.
    • stripComments

      public static Reader stripComments(InputStream json)
      Strips comments from the json in the inputstream. Assumes UTF-8 encoding.
      Parameters:
      json - the JSON-encoded data
      Returns:
      a reader that strips comments from json data provided as an input stream.
    • stripComments

      public static String stripComments(String json)
      Parameters:
      json - the JSON-encoded data
      Returns:
      a String with comments stripped from the provided json data.
    • stripComments

      public static Reader stripComments(Reader json)
      Parameters:
      json - the JSON-encoded data
      Returns:
      a reader that strips comments from json data provided as a reader.
    • stringifyJavascriptObject

      public static String stringifyJavascriptObject(Object object)
      Converts the provided javascript object to JSON string.

      If the object is a Map instance, it is stringified as key-value pairs, if it is a list, it is stringified as a list, otherwise the object is merely converted to string using the toString() method.

      Parameters:
      object - the object to stringify.
      Returns:
      the object as a JSON string
    • toModelNode

      public static org.jboss.dmr.ModelNode toModelNode(Object object)