RestController JSON response object with optional

2019-06-09 17:03发布

I'm using Spring RestController to receive JSON messages

To DeSerialize I have main object that represent JSON request with all properties and include sub objects that include also decimal values as 2.22 that are optional per message/type

I use Double variables, e.g.

public class TransactionVO {

Double amount;

public Double getAmount() {
   return amount;
}

In my main object:

public class MainVO {

TransactionVO transactionVO;

public Double getResponseAmount() {

  transactionVO == null || transactionVO.getAmount() == null ? 0 : responseVO.getAmount();    
}

My approach have overhead of null check and I assume I'm doing something wrong/not optimal, but how should I support optional decimal when DeSerialize JSON?

0条回答
登录 后发表回答