Java to Jackson JSON serialization: Money fields

后端 未结 7 1448
臣服心动
臣服心动 2020-12-04 12:24

Currently, I\'m using Jackson to send out JSON results from my Spring-based web application.

The problem I\'m having is trying to get all money fields to output with

7条回答
  •  死守一世寂寞
    2020-12-04 12:39

    I had the same issue and i had it formatted into JSON as a String instead. Might be a bit of a hack but it's easy to implement.

    private BigDecimal myValue = new BigDecimal("25.50");
    ...
    public String getMyValue() {
        return myValue.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }
    

提交回复
热议问题