Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-08-2018 10:08 AM
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.
11-08-2018 01:34 PM
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.
11-08-2018 02:11 PM
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 ?
11-12-2018 12:20 AM
Unfortunately no. As the class is already registered as an NodeEntity
, Neo4j-OGM wants to eager map it when it finds the type/label.
11-16-2018 09:40 PM
You might want to define models and model converters, to both validate and format via Jackson. But yeah, the OGM is the bottleneck in what you're trying to do. While it makes life a lot simpler, you have to abide by its node and relationship model. Luckily you can define those pretty freely, and with converters between e.g. "Neo4jModelVerbatim" to "Neo4jModelResponseView" to coerce from your nicely 3NF Neo4j data model to your denormalized JSON.
All the sessions of the conference are now available online