Class JSONUtil
java.lang.Object
org.revapi.configuration.JSONUtil
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 Summary
Modifier and TypeMethodDescriptionstatic org.jboss.dmr.ModelNode
convert
(com.fasterxml.jackson.databind.JsonNode node) static com.fasterxml.jackson.databind.JsonNode
convert
(org.jboss.dmr.ModelNode node) static boolean
isNullOrUndefined
(com.fasterxml.jackson.databind.JsonNode node) static com.fasterxml.jackson.databind.JsonNode
static com.fasterxml.jackson.databind.JsonNode
static String
stringifyJavascriptObject
(Object object) Converts the provided javascript object to JSON string.static Reader
stripComments
(InputStream json) Strips comments from the json in the inputstream.static InputStream
stripComments
(InputStream json, Charset charset) Deprecated.This ignores the charset and uses UTf-8.static Reader
stripComments
(Reader json) static String
stripComments
(String json) static org.jboss.dmr.ModelNode
toModelNode
(Object object) static String
toString
(com.fasterxml.jackson.databind.JsonNode json)
-
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
-
parse
- Throws:
IOException
-
toString
-
isNullOrUndefined
-
stripComments
Deprecated.This ignores the charset and uses UTf-8. UsestripComments(InputStream)
instead.- Parameters:
json
- the JSON-encoded datacharset
- the charset of the data- Returns:
- an input stream that strips comments from json data provided as an input stream.
-
stripComments
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
-
stripComments
-
stringifyJavascriptObject
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
-