4

Is there any way to serialize BigInteger field in plain format as String JavaScript object field, rather than Numeric in exponential notation (which is default behavior of Jackson)?

Ivan Sharamet
  • 317
  • 4
  • 15

2 Answers2

3

You could use a specific serializer defined with JsonSerialize annotation

https://fasterxml.github.io/jackson-databind/javadoc/2.9/com/fasterxml/jackson/databind/annotation/JsonSerialize.html

The problem is similar to this question:

Java to Jackson JSON serialization: Money fields

Klesun
  • 12,280
  • 5
  • 59
  • 52
NCH
  • 111
  • 3
  • 2
    This solution is good in case you know the property type in compile time. In my case, I have a generic class that in some cases, one of its properties might be a BigInt and I want it to be serialized as a string. My question is, how do I replace the default BigInt serializer with one of my own? (the generic type might be a List for example) – Modi Aug 13 '13 at 08:31
0

I assume this is the way:

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
...
@JsonSerialize(using = ToStringSerializer.class)
final private BigInteger serviceFee;
Klesun
  • 12,280
  • 5
  • 59
  • 52