Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT OverlayTypes Date and Long

I have some errors from Date and Long types and Overlay Types. Both uses long which is not allowed in GWT JSNI. Date serializes as long via getTime().

What I am doing right now (and it seems to work) is:

FROM JAVA (Using Jackson to serialize to json)

Long myLong = new Long(50)
Date myDate = new Date();

public String getMyLong()
{
return String.valueOf(myLong);
}

public String getDate() {
return String.valueOf(date.getTime());
}

FROM GWT (Using OverlayTypes)

/*Returning a Long*/
private final native String _getEscaletaId()   /*-{ return this.escaletaId; }-*/; 
public final Long getEscaletaId() {return new Long(_getEscaletaId());}
/*Returning a Date*/
private final native String _getDate() /*-{ return this.date; }-*/; 
public final Date getDate() {return new Date(Long.valueOf(_getDate()));}

Is this the better approach to deal with long and other special types?

Thankyou.

like image 319
ramon_salla Avatar asked Nov 16 '10 21:11

ramon_salla


1 Answers

For dates, there's JsDate, a thin JSO wrapper around the JS Date object.

Longs are dicey because JavaScript doesn't have the concept of a long. All numbers are 53-bit doubles, a fact which bit Twitter recently.

like image 193
Jason Hall Avatar answered Nov 15 '22 00:11

Jason Hall