public class Json extends Object
JsonParser
, JsonGenerator
,
JsonParserFactory
and JsonGeneratorFactory
instances.
This lists only commonly used methods to create JsonParser
and JsonGenerator
objects, the corresponding factories
have all the methods to create these objects.
All the methods would locate a provider instance, which is returned by
the provider
method, and is used
to create JsonParser
, JsonGenerator
JsonParserFactory
and JsonGeneratorFactory
instances.
For example, a JSON parser for parsing an empty array could be created as follows:
StringReader reader = new StringReader("[]");
JsonParser parser = Json.createParser(reader);
All of the methods in this class are safe for use by multiple concurrent threads.
Modifier and Type | Method and Description |
---|---|
static JsonGenerator |
createGenerator(OutputStream out)
Creates a JSON generator which can be used to write JSON text to the
specified byte stream.
|
static JsonGenerator |
createGenerator(Writer writer)
Creates a JSON generator which can be used to write JSON text to the
specified character stream.
|
static JsonGeneratorFactory |
createGeneratorFactory()
Creates a generator factory which can be used to create
JsonGenerator . |
static JsonGeneratorFactory |
createGeneratorFactory(JsonConfiguration config)
Creates a generator factory which can be used to create
JsonGenerator . |
static JsonParser |
createParser(InputStream in)
Creates a JSON parser from the specified byte stream.
|
static JsonParser |
createParser(Reader reader)
Creates a JSON parser from the specified character stream
|
static JsonParserFactory |
createParserFactory()
Creates a parser factory which can be used to create
JsonParser . |
static JsonParserFactory |
createParserFactory(JsonConfiguration config)
Creates a parser factory which can be used to create
JsonParser . |
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()
JsonParser
.public static JsonParserFactory createParserFactory(JsonConfiguration config)
JsonParser
.
The created parser factory is configured with the specified
configurationconfig
- configuration of the parser factoryIllegalArgumentException
- if a feature in the configuration
is not knownpublic static JsonGeneratorFactory createGeneratorFactory()
JsonGenerator
.public static JsonGeneratorFactory createGeneratorFactory(JsonConfiguration config)
JsonGenerator
.
The created generator factory is configured with the specified
configuration.config
- configuration of the generator factoryIllegalArgumentException
- if a feature in the configuration
is not knownCopyright © 2013. All Rights Reserved.