Search code examples
javajsonorientdbvertex

Obtain a String in Json format from a Vertex instance


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"}

Solution

  • You could use

    OrientVertex v=g.getVertex("#9:0");
    ODocument d=v.getRecord();
    String json=d.toJSON();
    

    Hope it helps