Class Json
java.lang.Object
jdk.incubator.json.Json
This class provides static methods for parsing and generating JSON texts.
Successful parsing guarantees there are no syntax errors. Unsuccessful
parsing throws a
parse(String) and parse(char[]) produce a JsonValue
by parsing data adhering to the JSON syntax defined in
RFC 8259.
JsonValue root = Json.parse(jsonText);
JsonParseException. Note that duplicate names in
a JsonObject also result in this exception.
toDisplayString(JsonValue, String) produces a
JSON text representation of the given JsonValue suitable for display.
- Since:
- 28
- External Specifications
-
Method Summary
Modifier and TypeMethodDescriptionstatic JsonValueparse(char[] in) Parses and creates aJsonValuefrom the given JSON text.static JsonValueParses and creates aJsonValuefrom the given JSON text.static StringtoDisplayString(JsonValue value, String indent) Returns the String representation of the givenJsonValuethat conforms to the JSON syntax.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Method Details
-
parse
Parses and creates aJsonValuefrom the given JSON text. If parsing succeeds, it guarantees that the input text conforms to the JSON syntax. If the text contains any JSON object that has duplicate names, aJsonParseExceptionis thrown.JsonObjects preserve the order of members in the input JSON text.- Implementation Note:
JsonValues created by this method may produce their underlying value representation lazily.- Parameters:
in- the input JSON text asString. Non-null.- Returns:
- the parsed
JsonValue - Throws:
JsonParseException- if the input JSON text does not conform to the JSON text format or a JSON object containing duplicate names is encountered.NullPointerException- ifinisnull
-
parse
Parses and creates aJsonValuefrom the given JSON text. If parsing succeeds, it guarantees that the input text conforms to the JSON syntax. If the text contains any JSON object that has duplicate names, aJsonParseExceptionis thrown. After parsing, changes to the input array have no effect on the returnedJsonValue.JsonObjects preserve the order of their members declared in and parsed from the JSON text.- Implementation Note:
JsonValues created by this method may produce their underlying value representation lazily.- Parameters:
in- the input JSON text aschar[]. Non-null.- Returns:
- the parsed
JsonValue - Throws:
JsonParseException- if the input JSON text does not conform to the JSON text format or a JSON object containing duplicate names is encountered.NullPointerException- ifinisnull
-
toDisplayString
Returns the String representation of the givenJsonValuethat conforms to the JSON syntax. As opposed to the compact output returned byJsonValue.toString(), this method returns JSON text that is better suited for display. Theindentparameter specifies the indentation string used for each line and may contain only JSON insignificant whitespace characters: space (' '), horizontal tab ('\t'), line feed ('\n'), or carriage return ('\r').- Parameters:
value- theJsonValueto create the display string from. Non-null.indent- theStringfor the indentation. Non-null.- Returns:
- the String representation of the given
JsonValuethat conforms to the JSON syntax - Throws:
IllegalArgumentException- ifindentcontains characters other than insignificant whitespace characters.NullPointerException- ifvalueorindentisnull- See Also:
-