public abstract class JsonFactory extends Object
Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the JSON factory.
| Constructor and Description |
|---|
JsonFactory()
|
| Modifier and Type | Method and Description |
|---|---|
abstract JsonGenerator |
createJsonGenerator(OutputStream
Returns a new instance of a low-level JSON serializer for the given output stream and encoding.
|
abstract JsonGenerator |
createJsonGenerator(Writer
Returns a new instance of a low-level JSON serializer for the given writer.
|
JsonObjectParser |
createJsonObjectParser()
Creates an object parser which uses this factory to parse JSON data.
|
abstract JsonParser |
createJsonParser(InputStream
Returns a new instance of a low-level JSON parser for the given input stream.
|
abstract JsonParser |
createJsonParser(InputStream
Returns a new instance of a low-level JSON parser for the given input stream.
|
abstract JsonParser |
createJsonParser(Reader
Returns a new instance of a low-level JSON parser for the given reader.
|
abstract JsonParser |
createJsonParser(String
Returns a new instance of a low-level JSON parser for the given string value.
|
<T> T |
fromInputStream(InputStream
Parse and close an input stream as a JSON object, array, or value into a new instance of the given destination class using
JsonParser.
|
<T> T |
fromInputStream(InputStream
Parse and close an input stream as a JSON object, array, or value into a new instance of the given destination class using
JsonParser.
|
<T> T |
fromReader(Reader
Parse and close a reader as a JSON object, array, or value into a new instance of the given destination class using
JsonParser.
|
<T> T |
fromString(String
Parses a string value as a JSON object, array, or value into a new instance of the given destination class using
JsonParser.
|
byte[] |
toByteArray(Object
Returns a UTF-8 encoded byte array of the serialized JSON representation for the given item using
JsonGenerator.
|
String |
toPrettyString(Object
Returns a pretty-printed serialized JSON string representation for the given item using
JsonGenerator with
JsonGenerator.
|
String |
toString(Object
Returns a serialized JSON string representation for the given item using
JsonGenerator.
|
public abstract JsonParsercreateJsonParser(InputStream in) throws IOException
in - input stream
IOException
public abstract JsonParsercreateJsonParser(InputStream in, Charset charset) throws IOException
in - input stream
charset - charset in which the input stream is encoded or
null to let the parser detect the charset
IOException
public abstract JsonParsercreateJsonParser(String value) throws IOException
value - string value
IOException
public abstract JsonParsercreateJsonParser(Reader reader) throws IOException
reader - reader
IOException
public abstract JsonGeneratorcreateJsonGenerator(OutputStream out, Charset enc) throws IOException
out - output stream
enc - encoding
IOException
public abstract JsonGeneratorcreateJsonGenerator(Writer writer) throws IOException
writer - writer
IOException
public final JsonObjectParsercreateJsonObjectParser()
public final StringtoString(Object item) throws IOException
JsonGenerator.serialize(Object) .
item - data key/value pairs
IOException
public final StringtoPrettyString(Object item) throws IOException
JsonGenerator.serialize(Object) with
JsonGenerator.enablePrettyPrint() .
The specifics of how the JSON representation is made pretty is implementation dependent, and should not be relied on. However, it is assumed to be legal, and in fact differs from toString(Object) only by adding whitespace that does not change its meaning.
item - data key/value pairs
IOException
public final byte[] toByteArray(Objectitem) throws IOException
JsonGenerator.serialize(Object) .
item - data key/value pairs
IOException
public final <T> T fromString(Stringvalue, Class <T> destinationClass) throws IOException
JsonParser.parse(Class) .
value - JSON string value
destinationClass - destination class that has an accessible default constructor to use to create a new instance
IOException
public final <T> T fromInputStream(InputStreaminputStream, Class <T> destinationClass) throws IOException
JsonParser.parseAndClose(Class) .
Tries to detect the charset of the input stream automatically.
inputStream - JSON value in an input stream
destinationClass - destination class that has an accessible default constructor to use to create a new instance
IOException
public final <T> T fromInputStream(InputStreaminputStream, Charset charset, Class <T> destinationClass) throws IOException
JsonParser.parseAndClose(Class) .
inputStream - JSON value in an input stream
charset - Charset in which the stream is encoded
destinationClass - destination class that has an accessible default constructor to use to create a new instance
IOException
public final <T> T fromReader(Readerreader, Class <T> destinationClass) throws IOException
JsonParser.parseAndClose(Class) .
reader - JSON value in a reader
destinationClass - destination class that has an accessible default constructor to use to create a new instance
IOException