Jackson从字符串/纯数字格式解析双精度

46scxncf  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(716)

I have a filed, lets say something like this, which is double value boxed to native type or in string.

{ "field1" : 123.00 }

or

{"field1" : "123.00" }

and Corresponding Pojo:

class Response{
          Double field1;
}

Now, if its in String format, I see an error as shown below:

Caused by: java.lang.NoSuchFieldError: USE_FAST_DOUBLE_PARSER
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$DoubleDeserializer._parseDouble(NumberDeserializers.java:755)
    at com.fasterxml.jackson.databind.deser.std.NumberDeserializers$DoubleDeserializer.deserialize(NumberDeserializers.java:684)

Apparently the same thing works for Int or long for both string or pure numbers. Why does it fail for Double?
Is there any annotation to use to make it work for both formats? Or fix the issue for parsing from string?
Alternatively, it works using @Jsonsetter.
Thanks

b09cbbtk

b09cbbtk1#

上述错误是由Jackson依赖项中不兼容的版本(2.13.x与2.14)引起的,如@dpr所述。修复是为了纠正版本(使其对各种依赖项保持相同,如jackson-core,jackson-databind等),它对字符串和数字格式都有效,这是默认行为。

相关问题