最近(在过去几个小时左右)我开始得到这个异常堆栈:
org.codehaus.jackson.JsonParseException: Numeric value (1316835995324) out of range of int
at [Source: java.io.StringReader@5b082d45; line: 1, column: 642]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1291)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:385)
at org.codehaus.jackson.impl.JsonNumericParserBase.convertNumberToInt(JsonNumericParserBase.java:462)
at org.codehaus.jackson.impl.JsonNumericParserBase.getIntValue(JsonNumericParserBase.java:257)
at org.codehaus.jackson.map.deser.StdDeserializer._parseInteger(StdDeserializer.java:237)
at org.codehaus.jackson.map.deser.StdDeserializer$IntegerDeserializer.deserialize(StdDeserializer.java:838)
at org.codehaus.jackson.map.deser.StdDeserializer$IntegerDeserializer.deserialize(StdDeserializer.java:825)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:356)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:120)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:97)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$FieldProperty.deserializeAndSet(SettableBeanProperty.java:499)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$FieldProperty.deserializeAndSet(SettableBeanProperty.java:499)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:120)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:97)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$FieldProperty.deserializeAndSet(SettableBeanProperty.java:499)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$FieldProperty.deserializeAndSet(SettableBeanProperty.java:499)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:120)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:97)
at org.codehaus.jackson.map.deser.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:252)
at org.codehaus.jackson.map.deser.SettableBeanProperty$FieldProperty.deserializeAndSet(SettableBeanProperty.java:499)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:494)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:350)
at org.codehaus.jackson.map.ObjectReader._bindAndClose(ObjectReader.java:477)
at org.codehaus.jackson.map.ObjectReader.readValue(ObjectReader.java:253)
在反序列化java.util.Date
时会发生这种情况。有趣的部分是在输入流之前还有其他类似的Date
,它们不会引起任何问题。另外,我没有更改被序列化和反序列化的对象的字段。
有没有人知道为什么杰克逊试图将这个特定Date
值反序列化为int
(而不是long
)?
提前感谢任何见解。
编辑:我稍微调试了一下,看起来这是杰克逊试图处理的第一个Date
,即使它仍然在流的后期。我还看到杰克逊试图将这个数字强制为int
,尽管在处理过程中它被正确检测为long
。
编辑2:我对此进行了更多的调试并弄清楚了以下内容:只要我没有带有输入参数的setter,序列化/反序列化就可以正常工作,如下所示:
public void setSomeValue(int param)
{
// stuff
this.date = <result_value>
}
当我介绍这个setter时,Jackson会执行一个不同的代码路径并最终在阻塞中,它会尝试将long
(java.util.Date
)放入int
。< / p>
编辑3:将setter名称更改为与字段名称无关的内容可以解决问题。我仍然想知道原始方式是否按预期工作(如果是这样,它背后的想法是什么)还是一个错误。
答案 0 :(得分:2)
正确 - 预期的类型由具有最高优先级的mutator确定。因此,既然你的setter声明类型是'int',那就是Jackson所说的那样。它实际上必须,因为它将调用该setter;所以即使你碰巧有一个不同类型的字段(或者返回Date的getter),它也没有多大帮助,因为你不能将Date作为'int'传递给set方法。
INT_MIN int类型变量的最小值。 - 的 2147483648 强>
INT_MAX int类型变量的最大值。的 2147483647 强>
答案 1 :(得分:0)
是的,检查一下setter,将int改为long:
public void setSomeValue(long param)
{
this.date = param;
}