java Jackson:无法反序列化 START_OBJECT 令牌中的 Number 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14751756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hymanson: Can not deserialize instance of Number out of START_OBJECT token
提问by LancerX
My GWT service returns LinkedList<VisualData>
. This is how VisualData
looks:
我的 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;
}
}
I get the following excepion connected with field private Number 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.Hymanson.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"])
When I change private Number value
to private Object value
, all getters and setters I get:
当我更改private Number value
为 时private 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)
This second case is quite clear, the Object
class is not serializable. But why do I get Can not deserialize instance of java.lang.Number out of START_OBJECT token
?
第二种情况很清楚,Object
该类不可序列化。但为什么我得到Can not deserialize instance of java.lang.Number out of START_OBJECT token
?
回答by Perception
You won't be able to deserialize data into this object without supplying additional type information for your value
field. This is because the Number
class is abstract and cannot be instantiated. Changing the field to Object
will not help, since there are no writable fields on that class that Hymanson can deserialize data into.
如果不为您的value
字段提供其他类型信息,您将无法将数据反序列化到此对象中。这是因为Number
该类是抽象的,无法实例化。将字段更改为Object
将无济于事,因为该类上没有可写字段,Hyman逊可以将数据反序列化为。
You should change the field to be one of the concrete implementations of the Number
class (Integer
, Long
, Double
etc).
你应该改变的领域是的具体实现的一个Number
类(Integer
,Long
,Double
等)。