google cloud endpoints returning java long as string in JSON

72 views
Skip to first unread message

Naresh Pokuri

unread,
Jan 14, 2016, 1:33:13 AM1/14/16
to Google App Engine
I am using google app engine latest version 1.9.30 and I define my cloud endpoint as follows
@Api(name="app", version="v1", transformers={EndpointDateTransformer.class})
public class MyEndpoints {

    @ApiMethod(name="dummy", path="dummy", httpMethod=HttpMethod.GET)
    public Map<String, Object> dummy(){
        Map<String, Object> dummy = Maps.newHashMap();
        dummy.put("date", DateUtil.getCurrentTimestamp());
        dummy.put("number", 5L);
        return dummy;
    }

}
here EndpointDateTransformer converts Date to Long value and the JSON response from endpoint is
{
    "number": "5",
    "date": "1452751174672"
}

But if I change that 5L to 5 then I see JSON response as

{
    "number": 5,
    "date": "1452751174672"
}

Why cloud endpoints converting Long values as string in JSON. When I was working on old app engine versions 1.9.19 it used to work. Long rendered as long on JSON as well. Am I missing anything here?

Nick (Cloud Platform Support)

unread,
Jan 15, 2016, 12:22:22 PM1/15/16
to Google App Engine
This seems to be intended behaviour for Long values since they can actually exceed the max size of a Javascript number. Longs, according to the docs, can go to 263-1, while Javascript can only represent integers safely up to about 253. If you don't think you'll need numbers above 253, you could downgrade the "number" property to java int and still be safe.
Reply all
Reply to author
Forward
0 new messages