SDN + Spring Boot + Partial Response in REST API


(Prem) #1

Hi - We have a springboot application using SDN to access data from Neo4J. We already have APIs that would retireve the node information from Neo4J and present them in JSON format to the clients. We would like to implement "partial response" in the exposed REST API.

(i.e.) Instead of the server returning all the node properties, the client can request specific properties from a node.

/v1/models/{modelId} --> This would return all the properties of that specific node
/v1/models/{modelId}?fields=modelId,BucketName,FileName --> This would return only those three properties from the model.

The problem:
SDN was able to convert the Neo4J response to the domain object in Java, when I request the complete node (with all the properties). It does not convert to the domain object, if I request only the specific properties of the node.

This works - I get a Model Object
MATCH(m:Model {modelId:'a'})
RETURN m;

This DOES NOT work - I get no objects
MATCH(m:Model {modelId:'a'})
RETURN m.modelId, m.BucketName, m.FileName;

Not sure, if it is possible to fetch only some of the properties of a node and still convert them to its Object (annotated with NodeEntity).

Any help is appreciated.


(Gerrit Meier) #2

Hi,

Neo4j-OGM, the mapping framework behind Spring Data Neo4j, expects a node to get returned.
Good news here: Because you are using SDN, you can define a @QueryResult annotated class, that looks like your Model without the @NodeEntity annotation.
This transfer object can be constructed from the returned properties. but keep in mind that you have to name your Java class properties as the properties you return e.g. return...m.FileName as fileName if your field is named fileName in the Java class.


(Prem) #3

Hi @gerrit.meier - Thanks for the response. This specific node has many properties and any of them can be requested by the client. Would it be possible annotate the same java class with both NodeEntity and QueryResult ?


(Gerrit Meier) #4

Unfortunately no. As the class is already registered as an NodeEntity, Neo4j-OGM wants to eager map it when it finds the type/label.