FR: relax JSON parsing of TokenResponse (and JsonWebToken)
See original GitHub issueFrom michel.j…@e-office.com on November 28, 2012 00:30:25
Version of google-oauth-java-client (e.g. 1.5.0-beta)? 1.12.0
Java environment (e.g. Java 6, Android 2.3, App Engine)? AppEngine 1.7.3
Describe the problem. When consuming Microsoft Office365 OAuth services, the accessToken that is retrieved through:
AuthorizationCodeTokenRequest . execute() as per the sample, I get the error: number field formatted as a JSON string must use the @JsonString annotation How would you expect it to be fixed? In the JSONParser.java (from com.google.api.client.json) I commented out the Preconditions check, and now I have an accesstoken. And also the expires in has a value…
--------- start here -------
case VALUE_STRING:
// Preconditions.checkArgument(valueClass == null || !Number.class.isAssignableFrom(valueClass)
// || fieldContext != null && fieldContext.getAnnotation(JsonString.class) != null,
// "number field formatted as a JSON string must use the @JsonString annotation%s",
// contextString);
// TODO(yanivi): "special" values like Double.POSITIVE_INFINITY?
try {
return Data.parsePrimitiveValue(valueType, getText());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(contextString, e);
}
_Original issue: http://code.google.com/p/google-oauth-java-client/issues/detail?id=62_
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (5 by maintainers)

Top Related StackOverflow Question
I’m having the same problem (with the expires_in formatted as a string) when authorizing against the ExactOnline accounting API.
I had managed to work around the problem for the initial token request by creating my own ExactOnlineResponseToken class (which maps the expires_in to a String) and executing the tokenRequest as such:
I feel this is better than having to tinker with the libraries themselves. Unfortunately, I still get the error when the Credential automatically tries to refresh the token, because that code is hardcoded in the Credential and I can’t access it.
Any plans on making the library more permissive in the near future? I guess I could perform my own checks before each request, proactively refreshing the token when necessary, although that feels hackish.
Hi would like to know how do we modify the JSONParser claas or the TokenResponse class as they are in the jar file. Would be very helpful if anyone can share the steps.