I'm just in this method where I'm looking for all comments that each product brings, but the result would be an array of arrays, thus just wondering how could I, in a simple way turn this into a unique array.
Here my result on my swagger:
"all_comments": [
[
"comment 1 test a ver si sirve",
"comment 34 test a ver si sirve test 34"
],
["comment 2xxxxxxxxx",
"comment yyyyyyyy"
]
]
And the idea is to have kind of:
"all_comments": [
"comment 1 test a ver si sirve",
"comment 34 test a ver si sirve test 34",
"comment 2xxxxxxxxx",
"comment yyyyyyyy"
]
On one of my service implementation the method I set has this logic:
Service:
Map<String, Object> getAllComments() throws GeneralException
Service Implementation:
@Override
public Map<String, Object> getAllComments() throws GeneralException {
Map<String, Object> comments = new HashMap<>();
List<Set<Comments>> commentsSet = productRepository.findAll().stream()
.map(product -> product.getCommentsSet())
.collect(Collectors.toList());
comments.put("all_comments", commentsSet.stream()
.map(passList -> passList.stream()
.map(passSet -> passSet.getCommentBody()))
.collect(Collectors.toList()));
return comments;
}