public final class Json
extends java.lang.Object
The methods in this class locate a provider instance using the method
JsonProvider.provider()
. This class uses the provider instance
to create JSON processing objects.
The following example shows how to create a JSON parser to parse an empty array:
StringReader reader = new StringReader("[]");
JsonParser parser = Json.createParser(reader);
All the methods in this class are safe for use by multiple concurrent threads.
Modifier and Type | Method and Description |
---|---|
static JsonArrayBuilder |
createArrayBuilder()
Creates a JSON array builder
|
static JsonArrayBuilder |
createArrayBuilder(java.util.Collection<?> collection)
Creates a JSON array builder, initialized with the content of specified
collection . |
static JsonArrayBuilder |
createArrayBuilder(JsonArray array)
Creates a JSON array builder, initialized with the specified array
|
static JsonBuilderFactory |
createBuilderFactory(java.util.Map<java.lang.String,?> config)
Creates a builder factory for creating
JsonArrayBuilder
and JsonObjectBuilder objects. |
static JsonPatch |
createDiff(JsonStructure source,
JsonStructure target)
Generates a JSON Patch (RFC 6902)
from the source and target
JsonStructure . |
static JsonGenerator |
createGenerator(java.io.OutputStream out)
Creates a JSON generator for writing JSON to a byte stream.
|
static JsonGenerator |
createGenerator(java.io.Writer writer)
Creates a JSON generator for writing JSON to a character stream.
|
static JsonGeneratorFactory |
createGeneratorFactory(java.util.Map<java.lang.String,?> config)
Creates a generator factory for creating
JsonGenerator objects. |
static JsonMergePatch |
createMergeDiff(JsonValue source,
JsonValue target)
Generates a JSON Merge Patch (RFC 7396)
from the source and target
JsonValue s
which when applied to the source , yields the target . |
static JsonMergePatch |
createMergePatch(JsonValue patch)
Creates JSON Merge Patch (RFC 7396)
from specified
JsonValue . |
static JsonObjectBuilder |
createObjectBuilder()
Creates a JSON object builder
|
static JsonObjectBuilder |
createObjectBuilder(JsonObject object)
Creates a JSON object builder, initialized with the specified object.
|
static JsonObjectBuilder |
createObjectBuilder(java.util.Map<java.lang.String,?> map)
Creates a JSON object builder, initialized with the data from specified
map . |
static JsonParser |
createParser(java.io.InputStream in)
Creates a JSON parser from a byte stream.
|
static JsonParser |
createParser(java.io.Reader reader)
Creates a JSON parser from a character stream.
|
static JsonParserFactory |
createParserFactory(java.util.Map<java.lang.String,?> config)
Creates a parser factory for creating
JsonParser objects. |
static JsonPatch |
createPatch(JsonArray array)
Creates a JSON Patch (RFC 6902)
from the specified operations.
|
static JsonPatchBuilder |
createPatchBuilder()
Creates a JSON Patch builder (RFC 6902).
|
static JsonPatchBuilder |
createPatchBuilder(JsonArray array)
Creates a JSON Patch builder
(RFC 6902),
initialized with the specified operations.
|
static JsonPointer |
createPointer(java.lang.String jsonPointer)
Creates JSON Pointer (RFC 6901)
from given
jsonPointer string. |
static JsonReader |
createReader(java.io.InputStream in)
Creates a JSON reader from a byte stream.
|
static JsonReader |
createReader(java.io.Reader reader)
Creates a JSON reader from a character stream.
|
static JsonReaderFactory |
createReaderFactory(java.util.Map<java.lang.String,?> config)
Creates a reader factory for creating
JsonReader objects. |
static JsonNumber |
createValue(java.math.BigDecimal value)
Creates a JsonNumber.
|
static JsonNumber |
createValue(java.math.BigInteger value)
Creates a JsonNumber.
|
static JsonNumber |
createValue(double value)
Creates a JsonNumber.
|
static JsonNumber |
createValue(int value)
Creates a JsonNumber.
|
static JsonNumber |
createValue(long value)
Creates a JsonNumber.
|
static JsonNumber |
createValue(java.lang.Number value)
Creates a JsonNumber.
|
static JsonString |
createValue(java.lang.String value)
Creates a JsonString.
|
static JsonWriter |
createWriter(java.io.OutputStream out)
|
static JsonWriter |
createWriter(java.io.Writer writer)
|
static JsonWriterFactory |
createWriterFactory(java.util.Map<java.lang.String,?> config)
Creates a writer factory for creating
JsonWriter objects. |
static java.lang.String |
decodePointer(java.lang.String escaped)
Decodes a passed JSON-pointer string as defined by RFC 6901.
|
static java.lang.String |
encodePointer(java.lang.String pointer)
Encodes (escapes) a passed string as defined by RFC 6901.
|
public static JsonParser createParser(java.io.Reader reader)
reader
- i/o reader from which JSON is to be readpublic static JsonParser createParser(java.io.InputStream in)
in
- i/o stream from which JSON is to be readJsonException
- if encoding cannot be determined
or i/o error (IOException would be cause of JsonException)public static JsonGenerator createGenerator(java.io.Writer writer)
writer
- a i/o writer to which JSON is writtenpublic static JsonGenerator createGenerator(java.io.OutputStream out)
out
- i/o stream to which JSON is writtenpublic static JsonParserFactory createParserFactory(java.util.Map<java.lang.String,?> config)
JsonParser
objects.
The factory is configured with the specified map of provider specific
configuration properties. Provider implementations should ignore any
unsupported configuration properties specified in the map.config
- a map of provider specific properties to configure the
JSON parsers. The map may be empty or nullpublic static JsonGeneratorFactory createGeneratorFactory(java.util.Map<java.lang.String,?> config)
JsonGenerator
objects.
The factory is configured with the specified map of provider specific
configuration properties. Provider implementations should ignore any
unsupported configuration properties specified in the map.config
- a map of provider specific properties to configure the
JSON generators. The map may be empty or nullpublic static JsonWriter createWriter(java.io.Writer writer)
writer
- to which JSON object or array is writtenpublic static JsonWriter createWriter(java.io.OutputStream out)
object
or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using UTF-8 encoding.out
- to which JSON object or array is writtenpublic static JsonReader createReader(java.io.Reader reader)
reader
- a reader from which JSON is to be readpublic static JsonReader createReader(java.io.InputStream in)
in
- a byte stream from which JSON is to be readpublic static JsonReaderFactory createReaderFactory(java.util.Map<java.lang.String,?> config)
JsonReader
objects.
The factory is configured with the specified map of provider specific
configuration properties. Provider implementations should ignore any
unsupported configuration properties specified in the map.config
- a map of provider specific properties to configure the
JSON readers. The map may be empty or nullpublic static JsonWriterFactory createWriterFactory(java.util.Map<java.lang.String,?> config)
JsonWriter
objects.
The factory is configured with the specified map of provider specific
configuration properties. Provider implementations should ignore any
unsupported configuration properties specified in the map.config
- a map of provider specific properties to configure the
JSON writers. The map may be empty or nullpublic static JsonArrayBuilder createArrayBuilder()
public static JsonArrayBuilder createArrayBuilder(JsonArray array)
array
- the initial array in the builderpublic static JsonArrayBuilder createArrayBuilder(java.util.Collection<?> collection)
collection
.
If the @{code collection} contains Optional
s then resulting JSON array builder
contains the value from the collection
only if the Optional
is not empty.collection
- the initial data for the builderjava.lang.IllegalArgumentException
- if the value from the collection
cannot be converted
to the corresponding JsonValue
public static JsonObjectBuilder createObjectBuilder()
public static JsonObjectBuilder createObjectBuilder(JsonObject object)
object
- the initial object in the builderpublic static JsonObjectBuilder createObjectBuilder(java.util.Map<java.lang.String,?> map)
map
.
If the @{code map} contains Optional
s then resulting JSON object builder
contains the key from the map
only if the Optional
is not empty.map
- the initial object in the builderjava.lang.IllegalArgumentException
- if the value from the map
cannot be converted
to the corresponding JsonValue
public static JsonPointer createPointer(java.lang.String jsonPointer)
jsonPointer
string.
jsonPointer
string defines a reference to the target itself.jsonPointer
string is non-empty, it must be a sequence of '/
' prefixed tokens.jsonPointer
- the valid escaped JSON Pointer stringjava.lang.NullPointerException
- if jsonPointer
is null
JsonException
- if jsonPointer
is not a valid JSON Pointerpublic static JsonPatchBuilder createPatchBuilder()
public static JsonPatchBuilder createPatchBuilder(JsonArray array)
array
- the initial patch operationspublic static JsonPatch createPatch(JsonArray array)
array
- patch operationspublic static JsonPatch createDiff(JsonStructure source, JsonStructure target)
JsonStructure
.
The generated JSON Patch need not be unique.source
- the sourcetarget
- the target, must be the same type as the sourcepublic static JsonMergePatch createMergePatch(JsonValue patch)
JsonValue
.patch
- the patchpublic static JsonMergePatch createMergeDiff(JsonValue source, JsonValue target)
JsonValue
s
which when applied to the source
, yields the target
.source
- the sourcetarget
- the targetpublic static JsonBuilderFactory createBuilderFactory(java.util.Map<java.lang.String,?> config)
JsonArrayBuilder
and JsonObjectBuilder
objects.
The factory is configured with the specified map of provider specific
configuration properties. Provider implementations should ignore any
unsupported configuration properties specified in the map.config
- a map of provider specific properties to configure the
JSON builders. The map may be empty or nullpublic static JsonString createValue(java.lang.String value)
value
- a JSON stringpublic static JsonNumber createValue(int value)
value
- a JSON numberpublic static JsonNumber createValue(long value)
value
- a JSON numberpublic static JsonNumber createValue(double value)
value
- a JSON numberpublic static JsonNumber createValue(java.math.BigDecimal value)
value
- a JSON numberpublic static JsonNumber createValue(java.math.BigInteger value)
value
- a JSON numberpublic static java.lang.String encodePointer(java.lang.String pointer)
pointer
- the JSON-pointer string to encodepublic static java.lang.String decodePointer(java.lang.String escaped)
escaped
- the JSON-pointer string to decodepublic static JsonNumber createValue(java.lang.Number value)
value
- a JSON number