To lift server performance, when we query some data and result is hug, in which case, large memory will be used to produce the result json string.
One solution is to use streaming JSON responses.
@Path("/fof/{userName}") @GET @Produces(MediaType.APPLICATION_JSON) public Response getFOF(final @PathParam("userName") String userName) throws JSONException { StreamingOutput stream = new StreamingOutput() { @Override public void write(OutputStream os) throws IOException, WebApplicationException { // TODO Auto-generated method stub JsonGenerator jg = objectMapper.getJsonFactory().createJsonGenerator(os, JsonEncoding.UTF8); jg.writeStartObject(); jg.writeFieldName("fofs"); jg.writeStartArray(); try (Transaction tx = template.getGraphDatabaseService().beginTx()) { Iterable<User> fofs = userRepo.getFriendsOfFriends(userName); Iterator<User> it = fofs.iterator(); while (it.hasNext()) { User fof = it.next(); // jg.writeString(fof.getName()); jg.writeObject(fof); } tx.success(); jg.writeEndArray(); jg.writeEndObject(); jg.flush(); jg.close(); } } }; return Response.ok().entity(stream).type(MediaType.APPLICATION_JSON).build(); }
Warning: jg.writeObject(fof) will write the whole user object to result, which is not my expected. I just want to partial properties in the User object while ingore others. How to satisify my needs?
the similar commands are
http://stackoverflow.com/questions/20978383/convert-same-pojo-into-json-and-xml-but-ignore-some-properties-for-json
https://github.com/FasterXML/jackson-databind/issues/95
The simple way is to manually marshell you expected properties likes
jg.writeStartObject(); jg.writeFieldName("name"); jg.writeString(fof.getName()); jg.writeFieldName("phoneNum"); jg.writeString(fof.getPhoneNumber()); jg.writeEndObject();
The result json for query
curl http://localhost:7474/fifo/user/fof/liwk
is
{"fofs":[{"name":"losiy","phoneNum":"15658653696"},{"name":"jack","phoneNum":null}]}
References
http://neo4j.com/docs/stable/server-unmanaged-extensions.html#server-unmanaged-extensions-streaming
相关推荐
Neo4j Vue 安装步骤 克隆或下载该库到本地 下载neo4j并安装到本地,启动neo4j服务 进入到该工程的根目录,输入命令:npm run update进行npm包的导入 使用命令:npm run dev启动该工程 默认端口是:8081 neo4j账号...
Neo4j Vue 安装步骤 克隆或下载该库到本地 下载neo4j并安装到本地,启动neo4j服务 进入到该工程的根目录,输入命令:npm run update进行npm包的导入 使用命令:npm run dev启动该工程 默认端口是:8081 neo4j账号...
connections = { default : 'restful-neo4j' , restful - neo4j : { module : 'sails-restful-neo4j' , type : 'json' , // expected response type (json | string | http) host : 'foo.myneo4j.com' , //
电影示例应用 如何一起使用Spring Boot,Spring Data和Neo4j。 Spring Data Neo4j可以在基于Spring的应用程序中方便地集成Neo4j。 它提供了对象图映射(OGM)功能以及Spring Data项目共有的其他功能。 笔记该项目...
neo4j:所有人的图表
DR $ docker run --name neo4j bitnami/neo4j:latestDocker撰写$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-neo4j/master/docker-compose.yml > docker-compose.yml$ docker-compose up...
imap2neo4j: imap2neo4j imapServer imapUsername imapPassword imapMailbox neo4jServer [neo4jUsername] [neo4jPassword] [paging, eg import by batches of 1000] [specific range of messages, eg 50
通过在 conf/neo4j-server.properties 中添加一行来配置 Neo4j: org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.example.unmanagedextension=/example 启动 Neo4j 服务器。 写评论 curl ...
Sublime Text 2/3 插件:Neo4j Sublime 是最好的跨平台编辑器之一,所以我想为什么不创建一个简单的 Neo4j 插件呢?... 编辑用户名和密码(默认为neo4j:neo) 结果显示在控制台中(Ctrl+~)打开C
schemaless-graphql-neo4j 将无类型的动态GraphQL查询转换为Cypher。 签出,以更好地查看您可以编写的查询。入门$ npm install schemaless-graphql-neo4j :warning: 图书馆尚未发布操场您可以开始使用开发人员游乐场...
NBD_Tutorials_Neo4J:PJATK NDB教程的Neo4J分配
egg-neo4j Neo4j用于鸡蛋框架。安装$ npm i egg-neo4j --save用法// {app_root}/config/plugin.jsexports . neo4j = { enable : true , package : 'egg-neo4j' ,} ;配置// {app_root}/config/config.default....
Neo4j Vue安装步骤克隆或下载该库到本地下载neo4j并安装到本地,启动neo4j服务进入到该工程的根目录,输入命令:npm run update进行npm包的导入使用命令:npm run dev启动该工程默认端口是:8081 neo4j账号信息: ...
Neo4j Neo4j 是一个高度可扩展、健壮(完全 ACID)的原生图形数据库。 Neo4j 被全球数以千计的领先企业、初创公司、企业和政府用于任务关键型应用程序。 使用存储库上的 Dockerfile,您就可以使用 docker neo4j ...
Neo4j 用于将Neo4j图形数据库作为Hackolade数据建模目标的插件。 Hackolade通过插件体系结构公开了其核心数据建模引擎。 每个插件都将Hackolade数据建模功能应用于特定的目标技术,无论是静态数据(数据库)还是...
适用于Neo4j的GORM 该项目使用Bolt Java驱动程序为Neo4j 3.x图形数据库实现 。 有关更多信息,请参见以下链接: 对于当前的开发版本,请参见以下链接:
适用于Node.js的Neo4j REST API包装器 主分支: 开发分支: 安装 npm install node-neo4j --save 用法 为了使用该库,您必须创建一个应用并添加或在本地安装它。 如果您使用的是OS XI,则强烈建议通过安装Neo4j。 ...
spring-data-neo4j:在使用Neo4j时提供支持以提高Java开发人员的生产率。 使用熟悉的Spring概念,例如用于核心API使用和轻量级存储库样式数据访问的模板类
Neo4j:对知识图谱查询的接口 QA:模板匹配,问句解析 mysite:系统网页 spider:爬虫,知识图谱创建 关系型数据库:存储用户业务信息 使用说明 Neo4j 将graph.db 拷贝到Neo4j的安装目录下的/data/databases中,eg:...
在neo4j中导入stackexchange 脚步: 从archive.org下载转储: : 使用Posts.xml &co在extract extracted/<name>/中extracted/<name>/您想要extracted/<name>/ 。 在目录中您可以在Linux上使用dtrx 你需要sudo pip3 ...