HttpParser/ObjectParser should support Type and InputStream #112
Labels
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
From yan...@google.com on May 11, 2012 07:38:26
External references, such as a standards document, or specification? http://javadoc.google-http-java-client.googlecode.com/hg/1.8.3-beta/com/google/api/client/http/HttpParser.html Java environments (e.g. Java 6, Android 2.3, App Engine, or All)? All Please describe the feature requested. Suppose you want to parse a response using List, where A is some class using @key for key/value pairs. parse(List.class) doesn't compile, so instead you can try this:
List result = (List) HttpParser.parse(List.class, null);
But this would parse it as a List which means each element which end up being some GenericData instead of A.
So we need some way of specifying that we want to parse into the type List. TypeToken from Google Guava provides an elegant way to specify the Type using:
new TypeToken<List>(){}.getType()
The missing piece is a parse method that accepts Type. We cannot change HttpParser because that would be a backwards-incompatible change. So I propose adding a new interface like this:
public interface HttpParser2 extends HttpParser {
Object parseType(HttpResponse response, Type dataType) throws IOException;
}
and add this to HttpResponse:
public Object parseAsType(Type dataType) throws IOException {
Original issue: http://code.google.com/p/google-http-java-client/issues/detail?id=112
The text was updated successfully, but these errors were encountered: