3

Jackson seems to be coercing all floats into doubles in any data structure that I am trying to serialize into JSON. Is there any way to avoid this behavior?

Float f = 50.1f;
System.out.println(f);                                 // 50.1
System.out.println(f.doubleValue());                   // 50.099998474121094
System.out.println(new ObjectMapper().valueToTree(f)); // 50.099998474121094 -- how to prevent this?

Using jackson-all-1.9.11.jar.

Chiraag Mundhe
  • 374
  • 7
  • 15

1 Answers1

0

You can use the custom Jackson serializer of your own as described in this link

Java to Jackson JSON serialization: Money fields

Community
  • 1
  • 1
Santhosh Gandhe
  • 6,900
  • 2
  • 23
  • 17