Deekshith Anand
Deekshith Anand

Reputation: 2662

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

Upvotes: 4

Views: 4458

Answers (1)

Deekshith Anand
Deekshith Anand

Reputation: 2662

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.

Upvotes: 6

Related Questions