Double totalPaymentAmount = Optional.ofNullable(wayfairMonthBill.getPaymentAmountDetailJson()) .filter(StringUtils::isNotBlank).map(paymentAmountDetailJson -> JSON .parseArray(paymentAmountDetailJson, WayfairMonthBillPaymentDetailCustom.class)) .map(paymentAmountDetails -> paymentAmountDetails.stream() .map(WayfairMonthBillPaymentDetailCustom::getPaymentAmounts).flatMap(Collection::stream).filter(Objects::nonNull) .mapToDouble(paymentAmount -> paymentAmount).sum()).orElse(0.0);