com.android.volley.toolbox
Class JsonRequest<T>

java.lang.Object
  extended by com.android.volley.Request<T>
      extended by com.android.volley.toolbox.JsonRequest<T>
Type Parameters:
T - JSON type of response expected
All Implemented Interfaces:
Comparable<Request<T>>
Direct Known Subclasses:
JsonArrayRequest, JsonObjectRequest

public abstract class JsonRequest<T>
extends Request<T>

A request for retrieving a T type response body at a given URL that also optionally sends along a JSON body in the request specified.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.volley.Request
Request.Method, Request.Priority
 
Constructor Summary
JsonRequest(int method, String url, String requestBody, Response.Listener<T> listener, Response.ErrorListener errorListener)
           
JsonRequest(String url, String requestBody, Response.Listener<T> listener, Response.ErrorListener errorListener)
          Deprecated. Use #JsonRequest(int, String, String, Listener, ErrorListener).
 
Method Summary
protected  void deliverResponse(T response)
          Subclasses must implement this to perform delivery of the parsed response to their listeners.
 byte[] getBody()
          Returns the raw POST or PUT body to be sent.
 String getBodyContentType()
           
 byte[] getPostBody()
          Deprecated. Use getBody().
 String getPostBodyContentType()
          Deprecated. Use getBodyContentType().
protected abstract  Response<T> parseNetworkResponse(NetworkResponse response)
          Subclasses must implement this to parse the raw network response and return an appropriate response type.
 
Methods inherited from class com.android.volley.Request
addMarker, cancel, compareTo, deliverError, getCacheEntry, getCacheKey, getHeaders, getMethod, getParams, getParamsEncoding, getPostParams, getPostParamsEncoding, getPriority, getRetryPolicy, getSequence, getTag, getTimeoutMs, getTrafficStatsTag, getUrl, hasHadResponseDelivered, isCanceled, markDelivered, parseNetworkError, setCacheEntry, setRequestQueue, setRetryPolicy, setSequence, setShouldCache, setTag, shouldCache, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonRequest

public JsonRequest(String url,
                   String requestBody,
                   Response.Listener<T> listener,
                   Response.ErrorListener errorListener)
Deprecated. Use #JsonRequest(int, String, String, Listener, ErrorListener).

Deprecated constructor for a JsonRequest which defaults to GET unless getPostBody() or Request.getPostParams() is overridden (which defaults to POST).


JsonRequest

public JsonRequest(int method,
                   String url,
                   String requestBody,
                   Response.Listener<T> listener,
                   Response.ErrorListener errorListener)
Method Detail

deliverResponse

protected void deliverResponse(T response)
Description copied from class: Request
Subclasses must implement this to perform delivery of the parsed response to their listeners. The given response is guaranteed to be non-null; responses that fail to parse are not delivered.

Specified by:
deliverResponse in class Request<T>
Parameters:
response - The parsed response returned by Request.parseNetworkResponse(NetworkResponse)

parseNetworkResponse

protected abstract Response<T> parseNetworkResponse(NetworkResponse response)
Description copied from class: Request
Subclasses must implement this to parse the raw network response and return an appropriate response type. This method will be called from a worker thread. The response will not be delivered if you return null.

Specified by:
parseNetworkResponse in class Request<T>
Parameters:
response - Response from the network
Returns:
The parsed response, or null in the case of an error

getPostBodyContentType

public String getPostBodyContentType()
Deprecated. Use getBodyContentType().

Overrides:
getPostBodyContentType in class Request<T>

getPostBody

public byte[] getPostBody()
Deprecated. Use getBody().

Description copied from class: Request
Returns the raw POST body to be sent.

Overrides:
getPostBody in class Request<T>

getBodyContentType

public String getBodyContentType()
Overrides:
getBodyContentType in class Request<T>

getBody

public byte[] getBody()
Description copied from class: Request
Returns the raw POST or PUT body to be sent.

Overrides:
getBody in class Request<T>