2

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

Deekshith Anand
  • 2,175
  • 1
  • 21
  • 24
  • It would be useful if you add the code that tries to serialize your JSon. Cheers! – Karl Nov 07 '22 at 05:53
  • 1
    You can go through this: https://stackoverflow.com/questions/40214080/force-spring-boot-jackson-deserializer-to-use-bigdecimal – Anuj Pathak Nov 07 '22 at 05:55
  • Can you also show the object mapper configuration in your code? – Jishnu Prathap Nov 07 '22 at 06:16
  • @Karl, I used this class return type in feign client. – Deekshith Anand Nov 07 '22 at 06:41
  • @JishnuPrathap it's the default ObjectMapper configs provided by spring boot. And the Response is being parsed from feign client. – Deekshith Anand Nov 07 '22 at 06:43
  • 4
    I think you might be mixing incompatible versions of the jackson jars. `StreamReadFeatrue.USE_FAST_DOUBLE_PARSER` was added in version 2.14 of the jackson-core library. Your error looks like you’re using a version prior to 2.14 of this jar together with other jars that expect at least version 2.14. – dpr Nov 07 '22 at 06:53
  • @dpr, you are right indeed, thank you! Yes, there was a version mismatch, and it works both for string and number format. – Deekshith Anand Nov 07 '22 at 11:27

1 Answers1

3

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.

Deekshith Anand
  • 2,175
  • 1
  • 21
  • 24