4

私の GWT サービスは を返しますLinkedList<VisualData>。これはどのようVisualDataに見えるかです:

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;
    }
}

field に関連する次の例外が発生しますprivate Number value

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: org.apache.catalina.connector.CoyoteInputStream@a0eb51; line: 1, column: 29] (through reference chain: org.jage.charts.client.VisualData["value"])

に変更private Number valueするとprivate Object value、取得するすべてのゲッターとセッター:

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)

この 2 番目のケースは非常に明確で、Objectクラスはシリアライズ可能ではありません。しかし、なぜ私は得るのCan not deserialize instance of java.lang.Number out of START_OBJECT tokenですか?

4

1 に答える 1

9

フィールドに追加の型情報を提供しないと、データをこのオブジェクトに逆シリアル化することはできませんvalue。これは、Numberクラスが抽象的でインスタンス化できないためです。ObjectJackson がデータを逆シリアル化できるクラスには書き込み可能なフィールドがないため、フィールドを に変更しても役に立ちません。

Numberフィールドをクラスの具体的な実装の 1 つ ( 、 など) に変更する必要がIntegerありますLongDouble

于 2013-02-07T17:23:56.680 に答える