当前位置: 首页 > 知识库问答 >
问题:

Jackson:无法反序列化START_OBJECT令牌外的Number实例

贝镜
2023-03-14

我的GWT服务返回LinkedList 。以下是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;
    }
}
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"])
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类是不可序列化的。但是为什么我得到不能反序列化START_OBJECT令牌中的java.lang.Number实例

共有1个答案

吕博耘
2023-03-14

如果不为value字段提供附加类型信息,则无法将数据反序列化到此对象中。这是因为number类是抽象的,不能实例化。将字段更改为object不会有帮助,因为该类上没有Jackson可以反序列化数据的可写字段。

应该将字段更改为number类(integerlongdouble等)的具体实现之一。

 类似资料: