cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Spring Boot REST with Spring Data neo4j return response in graph format

I am using neo4j SDN with Spring REST API endpoint where now I am responding the API response in JSON rest format which is like from model to JSON response but I want to return the response like in graph format and I can render them on you for visualization purpose.

I have node for Movie and Person who acted in that movie, When I search by movie name my API should return the response with Graph structure in JSON format so that I can easily render on UI.  

I would like view data same like a Neo4j browser.

Thanks in advance.

#spingDataNeo4j

3 REPLIES 3

mrksph
Node Clone

Hi, 

In our application, we also return some of the responses in graph format. What we do is map it right before returning the response. 

In our case, it involves applying recursive mapping as we have many levels of depth for our domain models.

Hope it helps!

@mrksph when you say mapping does it mean that traverse over each record and then map to relation, don't you think it will affect the performance, do you have any sample response.

I don't understand exactly what you mean when you say "map to relation"

What we do is: 
1) We obtain the Java Object as a response after executing a query against Neo4j.
2) We use a dedicated mapper class that receives the Java Object as an argument
3) We traverse each Object, map its properties to a Response Object then recursively, using the same method, map its children the same way

For example:

class TestService {
private TestRepository repository;

TestObject getTestObjectByCode(String code){
return repository.getByCode(code);
}
}

class TestMapper {

TestResponse map(TestObject source) {
TestResponse response = new TestResponse();
response.setCode(source.getCode());
response.setChildren(map(source.getChildren());
return response;
}

}