In a Java application with an OrientDB database, after I have a Vertex object, I need to extract its properties in a String object. This object must be in Json format. An example of expected result is:
{"@type":"d","@rid":"#13:1093","@version":1,"@class":"V_Notification","lastUpdateDate":"2016-07-20 16:45:31","lastUpdateUser":"#12:41","creationDate":"2016-07-20 16:45:31","creationUser":"#12:41","type":"user_added_to_share_made_upload","description":"user_added_to_share_made_upload","sphereId":"#16:18","out_E_NotificationUser":["#45:1091"],"deleted":false,"version":0,"isRead":false,"@fieldTypes":"lastUpdateDate=t,lastUpdateUser=x,creationDate=t,creationUser=x,out_E_NotificationUser=g"}
You could use
OrientVertex v=g.getVertex("#9:0");
ODocument d=v.getRecord();
String json=d.toJSON();
Hope it helps
You can try gson library and than use something like:
Gson gson = new Gson(); String jsonInString = gson.toJson(yourOrientObj);
Ref.: mkyong.com
I made an example to try your case:
@class:
V_Notification
Property:
description
Vertex v = graph.getVertex("#17:0");
Gson gson = new Gson();
String jsonInString = gson.toJson(v.getProperty("description").toString());
System.out.println("STAMPO = " + jsonInString);
This is my output:
PRINTED = "user_added_to_share_made_upload"
Hope it helps.
Regards.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.