2013-02-07 90 views
3

我的GWT服務返回LinkedList<VisualData>。這是怎麼VisualData如下:Jackson:無法反序列化START_OBJECT令牌中的數字實例

import javax.xml.bind.annotation.XmlRootElement; 
import com.google.gwt.user.client.rpc.IsSerializable; 

@XmlRootElement 
public class VisualData implements IsSerializable { 
    private Number value; 
    private long timestamp; 

    public VisualData() { 
    } 

    public VisualData(Number value, long timestamp) { 
     this.value = value; 
     this.timestamp = timestamp; 
    } 

    public long getTimestamp() { 
     return timestamp; 
    } 

    public Number getValue() { 
     return value; 
    } 

    public void setTimestamp(long timestamp) { 
     this.timestamp = timestamp; 
    } 

    public void setValue(Number value) { 
     this.value = value; 
    } 
} 

我得到場private Number value連接以下excepion。

SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container 
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.Number out of START_OBJECT token 
at [Source: [email protected]; line: 1, column: 29] (through reference chain: org.jage.charts.client.VisualData["value"]) 

當我改變private Number valueprivate Object value,所有的getter和setter方法獲取:

SEVERE: WebModule[/AgECharts]Exception while dispatching incoming RPC call 
com.google.gwt.user.client.rpc.SerializationException: Type 'org.jage.charts.client.VisualData' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = Value:{@type=xs:int, $=6}, timestamp:1360240281439 
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619) 

這第二種情況是很清楚,Object類是不可序列。但爲什麼我會得到Can not deserialize instance of java.lang.Number out of START_OBJECT token

+0

http://stackoverflow.com/questions/13592467/can-not-deserialize-instance-of-org-joda-time-datetime-or-localdate-out-of-start –

回答

8

如果不提供value字段的其他類型信息,將無法將數據反序列化到此對象中。這是因爲Number類是抽象的,不能實例化。將該字段更改爲Object將無濟於事,因爲該類中沒有可以將數據反序列化到數據的可寫字段。

您應該將該字段更改爲Number類(Integer,Long,Double等)的具體實現之一。

+0

+1肯定答案。 –

相關問題