我正在为我的rest服务使用谷歌云端点。我正在使用RestyGWT在GWT客户端中使用这些数据。
我注意到云端点会自动将一个长数据类型括在双引号中,这会在我尝试将RestyGWT转换为POJO时导致异常。
以下是我的示例代码。
@Api(name = "test")
public class EndpointAPI {
@ApiMethod(httpMethod = HttpMethod.GET, path = "test")
public Container test() {
Container container = new Container();
container.testLong = (long)3234345;
container.testDate = new Date();
container.testString = "sathya";
container.testDouble = 123.98;
container.testInt = 123;
return container;
}
public class Container {
public long testLong;
public Date testDate;
public String testString;
public double testDouble;
public int testInt;
}}
这是云端点作为JSON返回的内容。您可以看到testLong被序列化为" 3234345“而不是3234345。

我有以下问题。(1)如何删除长值中的双引号?(2)如何将字符串格式改为"yyyy-MMM-dd hh:mm:ss“?
向您致敬,Sathya
发布于 2013-05-23 22:47:33
您使用的是什么版本的restyGWT?你有没有尝试过1.4快照?我认为这是负责解析restygwt中长整型的代码(1.4),它可能会对你有所帮助:
public static final AbstractJsonEncoderDecoder<Long> LONG = new AbstractJsonEncoderDecoder<Long>() {
public Long decode(JSONValue value) throws DecodingException {
if (value == null || value.isNull() != null) {
return null;
}
return (long) toDouble(value);
}
public JSONValue encode(Long value) throws EncodingException {
return (value == null) ? getNullType() : new JSONNumber(value);
}
};
static public double toDouble(JSONValue value) {
JSONNumber number = value.isNumber();
if (number == null) {
JSONString val = value.isString();
if (val != null){
try {
return Double.parseDouble(val.stringValue());
}
catch(NumberFormatException e){
// just through exception below
}
}
throw new DecodingException("Expected a json number, but was given: " + value);
}
return number.doubleValue();
}https://stackoverflow.com/questions/15942022
复制相似问题