Wednesday, June 06, 2007

GWT and long types

I've been digging in further with GWT. I ran across an interesting situation with the support for the java primitive type of long. In my case, I wanted to communicate an identifier (ultimately an id from the database). Typically, I use longs for these ids. However, once I sent the id from my service to the GWT code I would lose precision on the id. For example, the id would be 1131768484235521818 but the GWT client would see the id as 1131768484235521000. The key difference here is that the last three digits were rounded off.

The GWT documentation does warn about this, I just hadn't read this particular part. In my case, this issue was solved by converting the long to a String before sending it to the GWT code in the browser.