Storing JSON objects in Java

863 views
Skip to first unread message

nandan parikh

unread,
Jun 8, 2015, 7:47:48 AM6/8/15
to orient-...@googlegroups.com
I tried storing the JSON object as string and it works fine.
But storing as a JSON object as object itself shows serialization error.

Code :

Vertex v = graph.addVertex(null);
JSONObject json = new JSONObject();

json.put("name","someone");
json.put("address","somewhere");

v.setProperty("data", json);
 ( v.setProperty("data",json.toString() --- this works fine )

This code shows serialization error.. Cannot serialize JSONObject!

Any method to store JSON Objects as Objects without converting to string?

Thanks.

W. Craig Trader

unread,
Jun 9, 2015, 3:22:19 PM6/9/15
to orient-...@googlegroups.com
Nandan ...

The Graph API is overlaid on top of the ODocument APIs.  For any OrientElement (ie: OrientVertex, OrientEdge), you can call getRecord() to get the backing ODocument object.  If you look at the ODocument class, there is a much wider selection of methods for moving data to and from JSON text. 

Note, JSON is a text data format, with many library implementations that will provide APIs to process text and produce Java objects. While Orient does provide the Jackson 2.2.X jars with their distribution, those APIs are largely used internally and are not incorporated into Orient's public API. Orient can't be expected to support every Java JSON implementation, when the JSON standard describes the text format and not internal binary representations.

- Craig -

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nandan parikh

unread,
Jun 12, 2015, 6:28:26 AM6/12/15
to orient-...@googlegroups.com
I figured out the solution , the solution to storing JSON Object is as follows:
I converted the Json object to json string. I stored the string in one of the vertex as its property.

Then when i wanted the value, i got back the value from the vertex in the form of a string. Then i converted it into JSON Object using Json serializing method.

Plus if you want the Object as some object of specific class, you will need to use GSON library to convert JSON object to some specific object.

Hope this helps anyone :)
Reply all
Reply to author
Forward
0 new messages