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)?

2 Answers 2

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

1
  • 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<BigInt> for example)
    – Modi
    Aug 13, 2013 at 8:31
0

I assume this is the way:

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
...
@JsonSerialize(using = ToStringSerializer.class)
final private BigInteger serviceFee;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.