如何反序列化并将所有数字转换为 Long ?
Jackson 反序列化并将所有数字(如果值在整数范围内)转换为整数,而不是转换为长整型。我想将所有值转换为 Long。 是否存在简单的问题解决方案?
The Jackson deserialize and cast to Integer all numbers if value in range of Integers instead it cast to Long. I would like to cast ALL values to Long.
Is it exist easy solution of issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Jackson 反序列化为您指定的类型,因此如果您将属性声明为 long 或 Long 类型,它会将其构造为 long。但也许您正在绑定到像
Map
这样的“无类型”结构?如果所有值都是Long
类型,您可以适当地声明类型,例如:或者可以为
Object.class
添加自定义反序列化器,并进行不同的处理(默认反序列化器是org.codehaus.jackson.map.deser.UntypedObjectDeserializer
)。如果我知道你实际上想要做什么可能会有所帮助 -
Integer
和Long
都是数字,所以通常区别并不重要......所以什么是需要多头的原因是什么?Jackson deserializes to type you tell it to, so if you declare property to be of type long or Long it would construct it as long. But maybe you are binding to "untyped" structure like
Map
? If all values are of typeLong
, you could just declare type appropriately, like:Alternatively might be able to add custom Deserializer for
Object.class
with different handling (default deserializer isorg.codehaus.jackson.map.deser.UntypedObjectDeserializer
).It might help if I knew what you are actually trying to do --
Integer
andLong
are both numbers, so often distinction does not matter a lot... so what is the reason to require Longs?