achrefB3 / google-api-java-client

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

@JsonString for numbers #122

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?

http://tools.ietf.org/html/rfc4627

Java environments (e.g. Java 6, Android 2.2, App Engine 1.3.7, or All)?

All.

Please describe the feature requested.

Currently we assume that 64-bit numbers are represented as Strings in the JSON 
wire format.  The reasoning was that JavaScript clients cannot handle 64-bit 
numbers properly, so they prefer numbers be stored as strings.  However, that 
doesn't represent the most general use of JSON.  For example, OAuth 2 uses a 
64-bit JSON number for the "expires_in" field.

The problem is that then there is no way to parse 64-bit (and higher precision) 
JSON numbers.  Another problem: it is unintuitive that an int field is stored 
as a JSON number but a long field is stored as a JSON string.

The proposal is to instead always assume Java numbers are stored as JSON 
number.  If someone wants to store a Java number as a JSON string instead they 
must add a new @JsonString annotation.

For example, this parses a JSON number:

{"value" : 12345768901234576890123457689012345768901234576890}

class A {
  @Key BigInteger value;
}

And this parses a JSON string:

{"value" : "12345768901234576890123457689012345768901234576890"}

class B {
  @Key @JsonString BigInteger value;
}

If there is a mismatch between the declared Java field and the JSON value, the 
parser will throw an IllegalArgumentException.  This will happen for example if 
one tries to use class A for the second example, or class B for the first 
example.  This ensures that serialization of the data class matches the 
original parsed JSON data.

Original issue reported on code.google.com by yan...@google.com on 14 Feb 2011 at 4:19

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/3989063/

Original comment by yan...@google.com on 14 Feb 2011 at 10:08

GoogleCodeExporter commented 9 years ago
Oops wrong code review #.  It should be: http://codereview.appspot.com/4167047/

Original comment by yan...@google.com on 14 Feb 2011 at 10:09

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 15 Feb 2011 at 2:34

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 18 Feb 2011 at 1:22