How to parse JSON on JTree and vice versa

I use Java, and I want to parse a complex JSON string (containing objects, arrays with values, and arrays of objects for JTree) and vice versa. I was able to create a method that parses the JSON string (using Jackson ObjectMapper and JsonNode ) in JTree, but now I want the tree to be editable. And once it has changed, I want it to be parsed into a JSON String or into my Java class represented by a JSON String. Is there any way to do this?

+4
source share
1 answer

I can advise you to use GSON ( https://sites.google.com/site/gson/gson-user-guide ) to convert your data into a complex JTree structure and vice versa. So you can grab the Java class represented by the JSON String from your tree and easily convert it to JSON using GSON .

As an example:

 ComplexTreeObject obj = new ComplexTreeObject(); Gson gson = new Gson(); String json = gson.toJson(obj); 
0
source

Source: https://habr.com/ru/post/1490844/


All Articles