Spring Data Neo4j mapping Yens algorithm result

Hi,

I want to execute Yen's algorithm using Query annotation in Spring Data. It works but I have problem with mapping the paths:

in option A: I'm mapping to List, it returns all of nodes in one list without separating paths

in option B: I'm using mapping to List<List> and it separates path bur returns only first nodes from all paths as list.

I want to map algorithm result to List<List> like:
[

[a,b,c],

[f,b],

[s,g,t,h],

] etc

Could you please help me how to do it? I was trying using nodes, collect function and also with another class containing only list of NodeName but nothing worked as expected.

Thank you

Hi, code snippets:

// base class
@Node
public class City {
    @Id
    @GeneratedValue
    private Long id;

    @NonNull
    private String name;
    @NonNull
    private String code;
}
// neo4j repository, example returning separated list, always with 1 node
public interface CityRepository extends Neo4jRepository<City, Long> {
@Query("MATCH (source:City {code: 'BCC'}), (target:City {code: 'LAX'})
CALL gds.shortestPath.yens.stream('projection', {
    sourceNode: source,
    targetNode: target,
    k: 20,
    relationshipWeightProperty: 'distance'
})
YIELD index, sourceNode, targetNode, nodeIds, path, totalCost, costs
RETURN nodes(path) as path")
List<List<City>> findPaths();
}

What does your Spring Data entities and repositories look like?

On the single path there are two types of node like:

city->village->city->village and ideally I want to parse only city nodes, I was trying list comprehension but it also does not work

RETURN [x in nodes(path) WHERE 'City' IN LABELS(x)]

Problem solved using neo4j client and custom mapping