Back to project page pokedex.
The source code is released under:
MIT License
If you think the Android project pokedex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.andrescanales.pokedex; /*from w ww . ja va 2 s . c o m*/ /** * Created by andrescanales on 10/31/14. */ import com.android.volley.NetworkResponse; import com.android.volley.ParseError; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.toolbox.HttpHeaderParser; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import java.io.UnsupportedEncodingException; public class GsonRequest<T> extends Request<T> { /** JSON parsing engine */ protected final Gson gson; /** class of type of response */ protected final Class<T> clazz; /** result listener */ private final Response.Listener<T> listener; public GsonRequest(String url, Class<T> clazz, Response.Listener<T> listener, Response.ErrorListener errorListener) { super(Method.GET, url, errorListener); this.clazz = clazz; this.listener = listener; this.gson = new Gson(); } @Override protected void deliverResponse(T response) { listener.onResponse(response); } @Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String json = new String( response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success( gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JsonSyntaxException e2) { return Response.error(new ParseError(e2)); } } }