Java object to javascript

212 views Asked by At

I have a core java project, in which I have to create a data visualization in form of a graph.

This data visualization (a graph) is dumped in HTML file(in Plantuml format), which renders the graph in visual graph.

Now I am looking for a way where I can dump this graph data structure as well(which is actually interlinked java objects) in some format, such that I can read it in java script/jquery thereby reconstructing the whole graph, along with loading the HTML file and update the graph in HTML dynamically, using the graph data structure based on some input from user.

Since plantuml doesn't support dynamic events.

And since the HTML file generated dynamically, so creating JSP and dynamically loading it on server is not feasible.

I have seen some answers suggesting use of JAXB, JSON, but the question wasn't exactly as I needed.

I am thinking to dump it in xml and then read that xml in java script.But not sure how good this idea is.

Is there a better way?

1

There are 1 answers

0
Sam R On

JavaScript is not good at reading XML. The ECMA-357 standard was designed for this, but is all but forgotten. You can still find it in Rhino, but that doesn't suit your purposes.

JSON is really the language to use these days.

GSON or Jackson are common libraries for turning Java objects into JSON.