Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpParser/ObjectParser should support Type and InputStream #112

Closed
wonderfly opened this issue Jan 9, 2015 · 5 comments
Closed

HttpParser/ObjectParser should support Type and InputStream #112

wonderfly opened this issue Jan 9, 2015 · 5 comments

Comments

@wonderfly
Copy link
Contributor

@wonderfly wonderfly commented Jan 9, 2015

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

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

From yan...@google.com on May 11, 2012 07:41:33

early proof of concept: http://codereview.appspot.com/6209053/

@wonderfly wonderfly self-assigned this Jan 9, 2015
@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

From yan...@google.com on May 11, 2012 08:02:05

Actually Ravi, can you take this please? I think Matthias is proposing to add something else to HttpParser, so we should probably merge his work into HttpParser2 also.

Note: we need TypeToken which unfortunately is part of Guava 12, which is not Java 5 compatible. So we're stuck in a position of either forking Guava to a Java 5 compatible build (big project), OR writing our own light-weight TypeToken implementation as part of google-http-client (easy).

Owner: rmis...@google.com
Cc: -rmis...@google.com yan...@google.com

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

From mlin...@google.com on May 23, 2012 08:18:02

Summary: HttpParser/ObjectParser should support Type and InputStream
Owner: mlin...@google.com

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

From mlin...@google.com on June 05, 2012 13:51:19

Status: Fixed

@wonderfly

This comment has been minimized.

Copy link
Contributor Author

@wonderfly wonderfly commented Jan 9, 2015

From yan...@google.com on August 17, 2012 04:52:55

Explanation for the InputStream/Reader benefit of this: HttpParser requires HttpResponse, whereas ObjectParser takes an InputStream or Reader. That makes it more generally useful. In particular, google-api-java-client is able to take advantage of this to implement parsing of batches of responses in a multipart response, and also for parsing push notifications.

Cc: jasonhall@google.com

@wonderfly wonderfly closed this Jan 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.