Java to Jackson JSON serialization: Money fields

后端 未结 7 1447
臣服心动
臣服心动 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:31

    You can use @JsonFormat annotation with shape as STRING on your BigDecimal variables. Refer below:

     import com.fasterxml.jackson.annotation.JsonFormat;
    
      class YourObjectClass {
    
          @JsonFormat(shape=JsonFormat.Shape.STRING)
          private BigDecimal yourVariable;
    
     }
    

提交回复
热议问题