CHJani / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

'totalResults' field in a JSON query has changed type to string from number #307

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-api-java-client (e.g. 1.5.0-beta)?

google-api-java-client 1.5.0-beta
google-api-services-customsearch-v1-1.2.2-beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?

Android 2.3.3

Describe the problem.

I submit a CustomSearch query in Java using the above libraries. This has 
returned results ok and displayed them in my Android app until about 9 days 
ago. Now the query returns with a JSON result but the value for the 
'totalResults' field is of type string rather than number (i.e. it now returns 
"185000", but used to return 185000) and as a result an 
IllegalArgumentException is thrown when the JSON parser tries to convert the 
"185000" to the expected type of number. I checked the source code for 
google-api-services-customsearch-v1-1.2.2-beta and in Query.java the "private 
Integer totalResults" field is marked with the annotation 
"@Key("totalResults")" - see line 217. I assume this should now be "private 
String totalResults".

I manually entered my query in a browser, having replaced MY_APP_KEY with my 
app key and MY_CSE_ID with my custom search engine identifier:

"https://www.googleapis.com/customsearch/v1?key=MY_APP_KEY&cx=MY_CSE_ID&q=the+on
ly+problem&alt=json"

and it returns this (top and bottom ommitted for clarity but you can run the 
query yourself and see):

"queries": {
  "nextPage": [
   {
    "title": "Google Custom Search - the only problem",
    "totalResults": "185000",

The 'totalResults' field is now a string. The example on this page 
http://code.google.com/apis/customsearch/v1/using_rest.html shows the 
'totalResults' field as a number type.

How would you expect it to be fixed?

Update the google-api-services-customsearch-v1 library to use the new type - I 
guess the other implementations of this library (PHP, Python, Ruby) may need 
updating too...

Original issue reported on code.google.com by chewielo...@gmail.com on 30 Sep 2011 at 3:39

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 30 Sep 2011 at 4:14

GoogleCodeExporter commented 9 years ago
Indeed we should be generating String as the type for totalResults fields.  See 
the discovery doc:

https://www.googleapis.com/discovery/v1/apis/customsearch/v1/rest

totalResults: {
type: "string"
format: "int64"
}

Ravi, please check if this is a bug in the code generator, or a breaking 
server-side change that we need to accomodate by generating a new client lib 
for customsearch.

Original comment by yan...@google.com on 30 Sep 2011 at 4:25

GoogleCodeExporter commented 9 years ago
I generated a new client lib for custom search and updated the APIs wiki:
http://code.google.com/p/google-api-java-client/wiki/APIs#CustomSearch_API

The totalResults field now looks like this:

@Key("totalResults") @JsonString
  private Long totalResults;

Original comment by rmis...@google.com on 30 Sep 2011 at 6:08