Details
Description
When we use JsonHierarchicalStreamDriver to serialize to json string, Long, Integer,.. shows as a number without ", but when the return type is BigDecimal or BigInteger, it adds ". Example:
- Long
{"valor":1} - BigDecimal
{"valor":"1"}
To solve it, we are extending JsonWriter and override these functions:
@Override
public void startNode(String name, Class clazz) {
this.currentClass = clazz;
super.startNode(name, clazz);
}
@Override
protected void addValue(String value, Type type) {
if(currentClass.isAssignableFrom(BigDecimal.class)
|| currentClass.isAssignableFrom(BigInteger.class))
type = Type.NUMBER;
super.addValue(value, type);
}
Well, the appropriate method to overload would have been getType. Unfortunately it was private. Changed to protected now.
Nevertheless, BigInteger and BigDecimal are now handled directly.