开发者

GWT OverlayTypes Date and Long

开发者 https://www.devze.com 2023-01-25 04:46 出处:网络
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().

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 Lo开发者_如何学编程ng(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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号