0

I am receiving the JSONArray below,

[
    {
        "test": "Nivea Men",
        "category": null,
        "stock": null,
        "promoBundle": true,
        "discountPrice": 12.5
    },
    {
        "test": "Vaseline",
        "category": null,
        "stock": null,
        "promoBundle": true,
        "discountPrice": 12.5
    },
    {
        "test": "Blueband",
        "category": null,
        "stock": null,
        "promoBundle": true,
        "discountPrice": 12.5
    }
]

How can I extract a single object like discountPrice and introduce it to a if statement to check if is null or not and perform some logic.

I know the way how to loop through a list of items and add them to an array like. And also extract a single String value and map it to an AtomicReference

AtomicReference<String> territory = new AtomicReference<>("");
List <String> itemData = new ArrayList<>();
cart.getItems().forEach(pt -> {
  itemData.add(pt.getItemId());
  territory.set(pt.getTerritory());
});

but how can I extract only a single value of type double without adding it to an array list?. Any help is appreciated. I have tried tried

  AtomicReference<Double> discountPrice  = new AtomicReference<>((double) 0);
    listItems.forEach(dc->{
      discountPRice.set(dc.getDiscountPrice());
    });

Passing the discountPrice after extracting it

 cart.getItems().forEach(
      cartItem -> {
          CreateOrderDto.ItemDto item = CreateOrderDto.ItemDto();
          item.setDiscountPrice(discountPrice);

        }

but whenever I try to access the discount amount from somewhere else it prompts me to Change 1st parameter of method setDiscountPrice from Double to AtomicReference<Double>, and I don't want to change it I want it to remain as double. Any help is appreciated

justrying
  • 69
  • 7

0 Answers0