javax.json
Class Json

java.lang.Object
  extended by javax.json.Json

public class Json
extends Object

Factory to create JsonParser, JsonGenerator, JsonParserFactory and JsonGeneratorFactory instances.

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.

Author:
Jitendra Kotamraju

Constructor Summary
Json()
           
 
Method Summary
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(OutputStream out, JsonConfiguration config)
          Creates a JSON generator which can be used to write JSON text to the specified byte stream.
static JsonGenerator createGenerator(OutputStream out, String encoding)
          Creates a JSON generator which can be used to write JSON text to the specified byte stream.
static JsonGenerator createGenerator(OutputStream out, String encoding, JsonConfiguration config)
          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 JsonGenerator createGenerator(Writer writer, JsonConfiguration config)
          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(InputStream in, JsonConfiguration config)
          Creates a JSON parser from the specified byte stream.
static JsonParser createParser(InputStream in, String encoding)
          Creates a JSON parser from the specified byte stream.
static JsonParser createParser(InputStream in, String encoding, JsonConfiguration config)
          Creates a JSON parser from the specified byte stream.
static JsonParser createParser(JsonArray array)
          Creates a JSON parser from the specified JSON array.
static JsonParser createParser(JsonArray array, JsonConfiguration config)
          Creates a JSON parser from the specified JSON array.
static JsonParser createParser(JsonObject object)
          Creates a JSON parser from the specified JSON object.
static JsonParser createParser(JsonObject obj, JsonConfiguration config)
          Creates a JSON parser from the specified JSON object.
static JsonParser createParser(Reader reader)
          Creates a JSON parser from the specified character stream
static JsonParser createParser(Reader reader, JsonConfiguration config)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Json

public Json()
Method Detail

createParser

public static JsonParser createParser(Reader reader)
Creates a JSON parser from the specified character stream

Parameters:
reader - i/o reader from which JSON is to be read

createParser

public static JsonParser createParser(Reader reader,
                                      JsonConfiguration config)
Creates a JSON parser from the specified character stream. The created parser is configured with the specified configuration.

Parameters:
reader - i/o reader from which JSON is to be read
config - configuration of the parser
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createParser

public static JsonParser createParser(InputStream in)
Creates a JSON parser from the specified byte stream. The character encoding of the stream is determined as per the RFC.

Parameters:
in - i/o stream from which JSON is to be read
Throws:
JsonException - if encoding cannot be determined or i/o error

createParser

public static JsonParser createParser(InputStream in,
                                      String encoding)
Creates a JSON parser from the specified byte stream. The bytes of the stream are decoded to characters using the specified encoding.

Parameters:
in - i/o stream from which JSON is to be read
encoding - the name of character encoding of the stream.
Throws:
JsonException - if the named encoding is not supported. The cause of the exception would be UnsupportedEncodingException
See Also:
Charset

createParser

public static JsonParser createParser(InputStream in,
                                      JsonConfiguration config)
Creates a JSON parser from the specified byte stream. The created parser is configured with the specified configuration. The character encoding of the stream is determinedas per the RFC

Parameters:
in - i/o stream from which JSON is to be read
config - configuration of the parser
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createParser

public static JsonParser createParser(InputStream in,
                                      String encoding,
                                      JsonConfiguration config)
Creates a JSON parser from the specified byte stream. The bytes of the stream are decoded to characters using the specified encoding. The created parser is configured with the specified configuration.

Parameters:
in - i/o stream from which JSON is to be read
encoding - the name of character encoding of the stream.
config - configuration of the parser
Throws:
JsonException - if the named encoding is not supported. The cause of the exception would be UnsupportedEncodingException
IllegalArgumentException - if a feature in the configuration is not known
See Also:
Charset

createParser

public static JsonParser createParser(JsonObject object)
Creates a JSON parser from the specified JSON object.

Parameters:
object - JSON object

createParser

public static JsonParser createParser(JsonObject obj,
                                      JsonConfiguration config)
Creates a JSON parser from the specified JSON object. The created parser is configured with the specified configuration.

Parameters:
obj - JSON object
config - configuration of the parser
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createParser

public static JsonParser createParser(JsonArray array)
Creates a JSON parser from the specified JSON array.

Parameters:
array - JSON array

createParser

public static JsonParser createParser(JsonArray array,
                                      JsonConfiguration config)
Creates a JSON parser from the specified JSON array. The created parser is configured with the specified configuration.

Parameters:
array - JSON array
config - configuration of the parser
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createGenerator

public static JsonGenerator createGenerator(Writer writer)
Creates a JSON generator which can be used to write JSON text to the specified character stream.

Parameters:
writer - a i/o writer to which JSON is written

createGenerator

public static JsonGenerator createGenerator(Writer writer,
                                            JsonConfiguration config)
Creates a JSON generator which can be used to write JSON text to the specified character stream. The created generator is configured with the specified configuration.

Parameters:
writer - i/o writer to which JSON is written
config - configuration of the generator
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createGenerator

public static JsonGenerator createGenerator(OutputStream out)
Creates a JSON generator which can be used to write JSON text to the specified byte stream.

Parameters:
out - i/o stream to which JSON is written

createGenerator

public static JsonGenerator createGenerator(OutputStream out,
                                            JsonConfiguration config)
Creates a JSON generator which can be used to write JSON text to the specified byte stream. Characters written to the stream are encoded into bytes using UTF-8 encoding. The created generator is configured with the specified configuration.

Parameters:
out - i/o stream to which JSON is written
config - configuration of the generator
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createGenerator

public static JsonGenerator createGenerator(OutputStream out,
                                            String encoding)
Creates a JSON generator which can be used to write JSON text to the specified byte stream. Characters written to the stream are encoded into bytes using the specified encoding.

Parameters:
out - i/o stream to which JSON is written
encoding - the name of character encoding of the stream.
Throws:
JsonException - if the named encoding is not supported. The cause of the exception would be UnsupportedEncodingException
See Also:
Charset

createGenerator

public static JsonGenerator createGenerator(OutputStream out,
                                            String encoding,
                                            JsonConfiguration config)
Creates a JSON generator which can be used to write JSON text to the specified byte stream. Characters written to the stream are encoded into bytes using the specified encoding. The created generator is configured with the specified configuration.

Parameters:
out - i/o stream to which JSON is written
encoding - the name of character encoding of the stream.
config - configuration of the generator
Throws:
JsonException - if the named encoding is not supported. The cause of the exception would be UnsupportedEncodingException
IllegalArgumentException - if a feature in the configuration is not known
See Also:
Charset

createParserFactory

public static JsonParserFactory createParserFactory()
Creates a parser factory which can be used to create JsonParser.

Returns:
JSON parser factory

createParserFactory

public static JsonParserFactory createParserFactory(JsonConfiguration config)
Creates a parser factory which can be used to create JsonParser. The created parser factory is configured with the specified configuration

Parameters:
config - configuration of the parser factory
Returns:
JSON parser factory
Throws:
IllegalArgumentException - if a feature in the configuration is not known

createGeneratorFactory

public static JsonGeneratorFactory createGeneratorFactory()
Creates a generator factory which can be used to create JsonGenerator.

Returns:
JSON generator factory

createGeneratorFactory

public static JsonGeneratorFactory createGeneratorFactory(JsonConfiguration config)
Creates a generator factory which can be used to create JsonGenerator. The created generator factory is configured with the specified configuration.

Parameters:
config - configuration of the generator factory
Returns:
JSON generator factory
Throws:
IllegalArgumentException - if a feature in the configuration is not known



Copyright © 2012 Oracle and/or its affiliates. All rights reserved.