public class Json extends 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 JsonBuilderFactory |
createBuilderFactory(Map<String,?> config)
Creates a builder factory for creating
JsonArrayBuilder
and JsonObjectBuilder objects. |
static JsonGenerator |
createGenerator(OutputStream out)
Creates a JSON generator for writing JSON to a byte stream.
|
static JsonGenerator |
createGenerator(Writer writer)
Creates a JSON generator for writing JSON to a character stream.
|
static JsonGeneratorFactory |
createGeneratorFactory(Map<String,?> config)
Creates a generator factory for creating
JsonGenerator objects. |
static JsonObjectBuilder |
createObjectBuilder()
Creates a JSON object builder
|
static JsonParser |
createParser(InputStream in)
Creates a JSON parser from a byte stream.
|
static JsonParser |
createParser(Reader reader)
Creates a JSON parser from a character stream.
|
static JsonParserFactory |
createParserFactory(Map<String,?> config)
Creates a parser factory for creating
JsonParser objects. |
static JsonReader |
createReader(InputStream in)
Creates a JSON reader from a byte stream.
|
static JsonReader |
createReader(Reader reader)
Creates a JSON reader from a character stream.
|
static JsonReaderFactory |
createReaderFactory(Map<String,?> config)
Creates a reader factory for creating
JsonReader objects. |
static JsonWriter |
createWriter(OutputStream out)
|
static JsonWriter |
createWriter(Writer writer)
|
static JsonWriterFactory |
createWriterFactory(Map<String,?> config)
Creates a writer factory for creating
JsonWriter objects. |
public static JsonParser createParser(Reader reader)
reader
- i/o reader from which JSON is to be readpublic static JsonParser createParser(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(Writer writer)
writer
- a i/o writer to which JSON is writtenpublic static JsonGenerator createGenerator(OutputStream out)
out
- i/o stream to which JSON is writtenpublic static JsonParserFactory createParserFactory(Map<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(Map<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(Writer writer)
writer
- to which JSON object or array is writtenpublic static JsonWriter createWriter(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(Reader reader)
reader
- a reader from which JSON is to be readpublic static JsonReader createReader(InputStream in)
in
- a byte stream from which JSON is to be readpublic static JsonReaderFactory createReaderFactory(Map<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(Map<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 JsonObjectBuilder createObjectBuilder()
public static JsonBuilderFactory createBuilderFactory(Map<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 nullCopyright © 1996-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.