@Test public void testParseNetworkResponseWithBadJson() { final String json = "{data: null"; final Map<String, String> headers = new HashMap<>(); headers.put(CONTENT_TYPE, "application/javascript; charset=" + CHARSET); try { final NetworkResponse networkResponse = new NetworkResponse( json.getBytes(CHARSET), headers); final Response<SampleData> response = request.parseNetworkResponse(networkResponse); assertFalse(response.isSuccess()); } catch (final UnsupportedEncodingException e) { fail(e.getMessage()); } }
@SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(final NetworkResponse response) { try { final String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success((T) gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (final UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (final JsonSyntaxException e) { return Response.error(new ParseError(e)); } }
GsonRequest extends JsonRfcCompliantListenableRequest<T> { @SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(final NetworkResponse response) { try { final String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success((T) gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (final UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (final JsonSyntaxException e) { return Response.error(new ParseError(e)); } } }
GsonRequest extends JsonRfcCompliantListenableRequest<T> { @SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(final NetworkResponse response) { try { final String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success((T) gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (final UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (final JsonSyntaxException e) { return Response.error(new ParseError(e)); } } GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final CancelListener cancelListener,
					@Nullable final String jsonBody);  GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final String jsonBody); }
GsonRequest extends JsonRfcCompliantListenableRequest<T> { @SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(final NetworkResponse response) { try { final String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success((T) gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (final UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (final JsonSyntaxException e) { return Response.error(new ParseError(e)); } } GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final CancelListener cancelListener,
					@Nullable final String jsonBody);  GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final String jsonBody); @Override String toString(); }
GsonRequest extends JsonRfcCompliantListenableRequest<T> { @SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(final NetworkResponse response) { try { final String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success((T) gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (final UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (final JsonSyntaxException e) { return Response.error(new ParseError(e)); } } GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final CancelListener cancelListener,
					@Nullable final String jsonBody);  GsonRequest(final int method, @NonNull final String url, @NonNull final Gson gson,
					@NonNull final Type clazz, @Nullable final Listener<T> listener,
					@Nullable final ErrorListener errListener,
					@Nullable final String jsonBody); @Override String toString();  }