public class JsonObjectParser implements ObjectParserParses JSON data into an data class of key/value pairs.
Implementation is thread-safe.
Sample usage:
static void setParser(HttpRequest request) {
request.setParser(new JsonObjectParser(new JacksonFactory()));
}
Implements
ObjectParserConstructors
JsonObjectParser(JsonFactory jsonFactory)
public JsonObjectParser(JsonFactory jsonFactory)| Parameter | |
|---|---|
| Name | Description |
jsonFactory |
JsonFactoryJSON factory |
JsonObjectParser(JsonObjectParser.Builder builder)
protected JsonObjectParser(JsonObjectParser.Builder builder)| Parameter | |
|---|---|
| Name | Description |
builder |
JsonObjectParser.Builderbuilder |
Methods
<T>parseAndClose(InputStream in, Charset charset, Class<T> dataClass)
public T <T>parseAndClose(InputStream in, Charset charset, Class<T> dataClass)Parses the given input stream into a new instance of the the given data class of key/value pairs and closes the input stream.
| Parameters | |
|---|---|
| Name | Description |
in |
InputStream |
charset |
Charset |
dataClass |
Class<T> |
| Returns | |
|---|---|
| Type | Description |
T |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
<T>parseAndClose(Reader reader, Class<T> dataClass)
public T <T>parseAndClose(Reader reader, Class<T> dataClass)Parses the given reader into a new instance of the the given data class of key/value pairs and closes the reader.
| Parameters | |
|---|---|
| Name | Description |
reader |
Reader |
dataClass |
Class<T> |
| Returns | |
|---|---|
| Type | Description |
T |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
getJsonFactory()
public final JsonFactory getJsonFactory()Returns the JSON factory.
| Returns | |
|---|---|
| Type | Description |
JsonFactory |
|
getWrapperKeys()
public Set<String> getWrapperKeys()Returns the unmodifiable set of wrapper keys for the JSON content.
| Returns | |
|---|---|
| Type | Description |
Set<String> |
|
parseAndClose(InputStream in, Charset charset, Type dataType)
public Object parseAndClose(InputStream in, Charset charset, Type dataType)Parses the given input stream into a new instance of the the given data type of key/value pairs and closes the input stream.
| Parameters | |
|---|---|
| Name | Description |
in |
InputStream |
charset |
Charset |
dataType |
Type |
| Returns | |
|---|---|
| Type | Description |
Object |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
parseAndClose(Reader reader, Type dataType)
public Object parseAndClose(Reader reader, Type dataType)Parses the given reader into a new instance of the the given data type of key/value pairs and closes the reader.
| Parameters | |
|---|---|
| Name | Description |
reader |
Reader |
dataType |
Type |
| Returns | |
|---|---|
| Type | Description |
Object |
|
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|