public abstract class JsonFactory
Abstract low-level JSON factory.
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.
Constructors
JsonFactory()
public JsonFactory()
Methods
<T>fromInputStream(InputStream inputStream, Class<T> destinationClass)
public final T <T>fromInputStream(InputStream inputStream, Class<T> destinationClass)
Parse and close an input stream as a JSON object, array, or value into a new instance of the given destination class using <xref uid="com.google.api.client.json.JsonParser.
Tries to detect the charset of the input stream automatically.
Name | Description |
inputStream | InputStream JSON value in an input stream |
destinationClass | Class<T> destination class that has an accessible default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
Type | Description |
IOException |
<T>fromInputStream(InputStream inputStream, Charset charset, Class<T> destinationClass)
public final T <T>fromInputStream(InputStream inputStream, Charset charset, Class<T> destinationClass)
Parse and close an input stream as a JSON object, array, or value into a new instance of the given destination class using <xref uid="com.google.api.client.json.JsonParser.
Name | Description |
inputStream | InputStream JSON value in an input stream |
charset | Charset Charset in which the stream is encoded |
destinationClass | Class<T> destination class that has an accessible default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
Type | Description |
IOException |
<T>fromReader(Reader reader, Class<T> destinationClass)
public final T <T>fromReader(Reader reader, Class<T> destinationClass)
Parse and close a reader as a JSON object, array, or value into a new instance of the given destination class using <xref uid="com.google.api.client.json.JsonParser.
Name | Description |
reader | Reader JSON value in a reader |
destinationClass | Class<T> destination class that has an accessible default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
Type | Description |
IOException |
<T>fromString(String value, Class<T> destinationClass)
public final T <T>fromString(String value, Class<T> destinationClass)
Parses a string value as a JSON object, array, or value into a new instance of the given destination class using <xref uid="com.google.api.client.json.JsonParser.
Name | Description |
value | String JSON string value |
destinationClass | Class<T> destination class that has an accessible default constructor to use to create a new instance |
Type | Description |
T | new instance of the parsed destination class |
Type | Description |
IOException |
createJsonGenerator(OutputStream out, Charset enc)
public abstract JsonGenerator createJsonGenerator(OutputStream out, Charset enc)
Returns a new instance of a low-level JSON serializer for the given output stream and encoding.
Name | Description |
out | OutputStream output stream |
enc | Charset encoding |
Type | Description |
JsonGenerator | new instance of a low-level JSON serializer |
Type | Description |
IOException |
createJsonGenerator(Writer writer)
public abstract JsonGenerator createJsonGenerator(Writer writer)
Returns a new instance of a low-level JSON serializer for the given writer.
Name | Description |
writer | Writer writer |
Type | Description |
JsonGenerator | new instance of a low-level JSON serializer |
Type | Description |
IOException |
createJsonObjectParser()
public final JsonObjectParser createJsonObjectParser()
Creates an object parser which uses this factory to parse JSON data.
Type | Description |
JsonObjectParser |
createJsonParser(InputStream in)
public abstract JsonParser createJsonParser(InputStream in)
Returns a new instance of a low-level JSON parser for the given input stream. The parser tries to detect the charset of the input stream by itself.
Name | Description |
in | InputStream input stream |
Type | Description |
JsonParser | new instance of a low-level JSON parser |
Type | Description |
IOException |
createJsonParser(InputStream in, Charset charset)
public abstract JsonParser createJsonParser(InputStream in, Charset charset)
Returns a new instance of a low-level JSON parser for the given input stream.
Name | Description |
in | InputStream input stream |
charset | Charset charset in which the input stream is encoded or |
Type | Description |
JsonParser | new instance of a low-level JSON parser |
Type | Description |
IOException |
createJsonParser(Reader reader)
public abstract JsonParser createJsonParser(Reader reader)
Returns a new instance of a low-level JSON parser for the given reader.
Name | Description |
reader | Reader reader |
Type | Description |
JsonParser | new instance of a low-level JSON parser |
Type | Description |
IOException |
createJsonParser(String value)
public abstract JsonParser createJsonParser(String value)
Returns a new instance of a low-level JSON parser for the given string value.
Name | Description |
value | String string value |
Type | Description |
JsonParser | new instance of a low-level JSON parser |
Type | Description |
IOException |
toByteArray(Object item)
public final byte[] toByteArray(Object item)
Returns a UTF-8 encoded byte array of the serialized JSON representation for the given item using JsonGenerator#serialize(Object).
Name | Description |
item | Object data key/value pairs |
Type | Description |
byte[] | byte array of the serialized JSON representation |
Type | Description |
IOException |
toPrettyString(Object item)
public final String toPrettyString(Object item)
Returns a pretty-printed serialized JSON string representation for the given item using 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.
Name | Description |
item | Object data key/value pairs |
Type | Description |
String | serialized JSON string representation |
Type | Description |
IOException |
toString(Object item)
public final String toString(Object item)
Returns a serialized JSON string representation for the given item using JsonGenerator#serialize(Object).
Name | Description |
item | Object data key/value pairs |
Type | Description |
String | serialized JSON string representation |
Type | Description |
IOException |