Package javax.json
Class Json
- java.lang.Object
-
- javax.json.Json
-
public class Json extends java.lang.Object
Factory class for creating JSON processing objects. This class provides the most commonly used methods for creating these objects and their corresponding factories. The factory classes provide all the various ways to create these objects.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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonArrayBuilder
createArrayBuilder()
Creates a JSON array builderstatic JsonBuilderFactory
createBuilderFactory(java.util.Map<java.lang.String,?> config)
Creates a builder factory for creatingJsonArrayBuilder
andJsonObjectBuilder
objects.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 creatingJsonGenerator
objects.static JsonObjectBuilder
createObjectBuilder()
Creates a JSON object builderstatic 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 creatingJsonParser
objects.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 creatingJsonReader
objects.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 creatingJsonWriter
objects.
-
-
-
Method Detail
-
createParser
public static JsonParser createParser(java.io.Reader reader)
Creates a JSON parser from a character stream.- Parameters:
reader
- i/o reader from which JSON is to be read- Returns:
- a JSON parser
-
createParser
public static JsonParser createParser(java.io.InputStream in)
Creates a JSON parser from a byte stream. The character encoding of the stream is determined as specified in RFC 4627.- Parameters:
in
- i/o stream from which JSON is to be read- Returns:
- a JSON parser
- Throws:
JsonException
- if encoding cannot be determined or i/o error (IOException would be cause of JsonException)
-
createGenerator
public static JsonGenerator createGenerator(java.io.Writer writer)
Creates a JSON generator for writing JSON to a character stream.- Parameters:
writer
- a i/o writer to which JSON is written- Returns:
- a JSON generator
-
createGenerator
public static JsonGenerator createGenerator(java.io.OutputStream out)
Creates a JSON generator for writing JSON to a byte stream.- Parameters:
out
- i/o stream to which JSON is written- Returns:
- a JSON generator
-
createParserFactory
public static JsonParserFactory createParserFactory(java.util.Map<java.lang.String,?> config)
Creates a parser factory for creatingJsonParser
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.- Parameters:
config
- a map of provider specific properties to configure the JSON parsers. The map may be empty or null- Returns:
- JSON parser factory
-
createGeneratorFactory
public static JsonGeneratorFactory createGeneratorFactory(java.util.Map<java.lang.String,?> config)
Creates a generator factory for creatingJsonGenerator
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.- Parameters:
config
- a map of provider specific properties to configure the JSON generators. The map may be empty or null- Returns:
- JSON generator factory
-
createWriter
public static JsonWriter createWriter(java.io.Writer writer)
- Parameters:
writer
- to which JSON object or array is written- Returns:
- a JSON writer
-
createWriter
public static JsonWriter createWriter(java.io.OutputStream out)
Creates a JSON writer to write a JSONobject
orarray
structure to the specified byte stream. Characters written to the stream are encoded into bytes using UTF-8 encoding.- Parameters:
out
- to which JSON object or array is written- Returns:
- a JSON writer
-
createReader
public static JsonReader createReader(java.io.Reader reader)
Creates a JSON reader from a character stream.- Parameters:
reader
- a reader from which JSON is to be read- Returns:
- a JSON reader
-
createReader
public static JsonReader createReader(java.io.InputStream in)
Creates a JSON reader from a byte stream. The character encoding of the stream is determined as described in RFC 4627.- Parameters:
in
- a byte stream from which JSON is to be read- Returns:
- a JSON reader
-
createReaderFactory
public static JsonReaderFactory createReaderFactory(java.util.Map<java.lang.String,?> config)
Creates a reader factory for creatingJsonReader
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.- Parameters:
config
- a map of provider specific properties to configure the JSON readers. The map may be empty or null- Returns:
- a JSON reader factory
-
createWriterFactory
public static JsonWriterFactory createWriterFactory(java.util.Map<java.lang.String,?> config)
Creates a writer factory for creatingJsonWriter
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.- Parameters:
config
- a map of provider specific properties to configure the JSON writers. The map may be empty or null- Returns:
- a JSON writer factory
-
createArrayBuilder
public static JsonArrayBuilder createArrayBuilder()
Creates a JSON array builder- Returns:
- a JSON array builder
-
createObjectBuilder
public static JsonObjectBuilder createObjectBuilder()
Creates a JSON object builder- Returns:
- a JSON object builder
-
createBuilderFactory
public static JsonBuilderFactory createBuilderFactory(java.util.Map<java.lang.String,?> config)
Creates a builder factory for creatingJsonArrayBuilder
andJsonObjectBuilder
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.- Parameters:
config
- a map of provider specific properties to configure the JSON builders. The map may be empty or null- Returns:
- a JSON builder factory
-
-