I am a newbie in WebClient. I want to consume a rest service and replace some value and return the result.
this is the response I get from rest service:
[
{
"type": "somthing",
"details": {
"d1": "va1",
"d2": "va2",
"d3": "va3"
}
},
{
.....
},
...
]
This is the result I want to return to the user. (the new value is something that I get from the user, so I have it as a parameter.)
[
{
"type": "somthing",
"details": {
"d1": "va1",
"d2": "va2",
**"d3": "Replace with new value"**
}
},
{
.....
},
...
]
Flux<Item> items= webClient.get()
.uri("------URL------")
.retrieve()
.bodyToFlux(Item.class)
Above code correctly return items from the rest service and traditionally I can use collectList().block()
to get a List and replace the value inside the object and return it.
I feel that it is an old-fashion way. Is there any better way to handle this situation by using WebClient functionality?
Thanks to @michalk I used map and it worked.
Flux<Item> items= webClient.get()
.uri("------URL------")
.retrieve()
.bodyToFlux(Item.class)..map(item-> {
item.getDetails().setDThree(request.getValue);
return item;
});