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?
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 type Long
, you could just declare type appropriately, like:
Map<String,Long> map = objectMapper.readValue(json, new TypeReference<Map<String,Long>>() { });
Alternatively might be able to add custom Deserializer for Object.class
with different handling (default deserializer is org.codehaus.jackson.map.deser.UntypedObjectDeserializer
).
It might help if I knew what you are actually trying to do -- Integer
and Long
are both numbers, so often distinction does not matter a lot... so what is the reason to require Longs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With