I have some DB data:
// sequence subject unit1 unit2 unit3
// '2' 'math1', 'root', 'root1', 'asdf'
// '3' 'math1', 'root', 'root1', '2fa'
// '4' 'math1', 'root', 'root2', '23fasdf'
// '5' 'math1', 'cosin', 'tan1', ''
// '6' 'math1', 'cosin', 'tan1', 'a'
// '7' 'math2', 'sigma', 'alt', '22'
// '8' 'math2', 'sigma', 'alt', '2fa'
// '9' 'math2', 'sigma', 'alt', ''
// '10 'math2', 'ak1', 'test', 'aaaf3'
// '11 'math2', 'ak2', 'test2', 'af3vv'
And I call the Spring Data JPA using findall()
like this:
List<Entity> call = findall()
How to I make a response like this:
[{
math1: [{
unit1: [{
root: [{
root1: ["asdf", "2fa"]
}]
}]
}]
}]
I tried:
Map<String, List<Entity>> listUp_subject = collect.stream()
.collect(Collectors.groupingBy(Entity::getSubject));
... and ...
Map<String, Set<Entity>> collect2 = collect.stream()
.collect(Collectors.groupingBy(Entity::getSubject, Collectors.mapping(Entity::new, Collectors.toSet())));
But I can't make like that using Java Stream or by another way. How to make it?