如何解决发送带有 BigDecimal 值的 POJO 返回 null
我有一个 Spring Feign 客户端,它使用 POST 将 POJO 对象发送到远程端点:
SaleRequestFactory obj = new SaleRequestFactory();
obj.setId(insertedTransaction.getId());
obj.setAmount(wpfRequestDTO.getAmount());
DTO:
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class SaleRequestFactory implements Serializable {
private static final long serialVersionUID = 1744050117179344127L;
private BigDecimal amount;
}
@FeignClient(name = "remote-service")
public interface NetClient {
@RequestMapping(method = RequestMethod.POST,value = "/engine/sale")
SaleResponseFactory setInitTransaction(SaleRequestFactory saleRequestFactory);
}
当我尝试获取金额时:
nested exception is java.lang.NullPointerException: Cannot invoke "java.math.BigDecimal.doubleValue()" because the return value of "org.SaleRequestFactory.getAmount()" is null] with root cause
java.lang.NullPointerException: Cannot invoke "java.math.BigDecimal.doubleValue()" because the return value of "org.SaleRequestFactory.getAmount()" is null
当收到 POST 请求时,Spring 是否可能没有正确转换 BigDecimal
?
我是否需要将值转换为 Integer
才能正确读取数字?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。