Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson parse Double from String/Pure Number Format

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

like image 470
Deekshith Anand Avatar asked Oct 17 '25 15:10

Deekshith Anand


1 Answers

The Error mentioned was caused by incompatible versions (2.13.x vs 2.14) in Jackson dependencies, as mentioned by @dpr. The fix was to correct versions (keep it same for various dependencies i.e. jackson-core,jackson-databind, etc.,) and it works for both string and number format which is the default behaviour.

like image 110
Deekshith Anand Avatar answered Oct 20 '25 05:10

Deekshith Anand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!