I wrote an application that takes a JSON file as configuration. Up to this point, I wrote the JSON config by hand. However, now I want to allow other users who are not familiar with JSON format to make their own configurations. There's only 3 types of objects that the configuration needs to store, but the user should be allowed to add multiple copies of these objects. I want to write a configuration application where the user can press a button such as "Add Type A" and an object of type A is populated with default values and visualized so that the user can select properties and edit them. I know how to write an application that does this, but I feel like I'm re-inventing the wheel. Does anyone know of an open-source Java library that I can use inside my config application to handle visualization and editing a JSON file? If I'm approaching this from completely the wrong direction, please let me know.
1 Answer
I'm tempted to say "don't fear to reinvent the wheel". But the fact is that there a bunch solutions available :
How do I convert an object to JSON representation (and vice-versa)
Java representation of JSON Object
Javascript to Java using JSON
among them, GSON looks fine.
For my personal experience, Yaml turned out to be an appropriate solution.
2 Comments
Code Whisperer
GSON works very well for conversion and has a very clean implementation (just function calls).
PentiumPro200
I'm currently using GSON and it works great. But I'm interested more in how the JSON file is visualized and edited by people without a software background. I thought maybe there would be a visual editor based on a grammar that allows one to easily add / edit nodes in the JSON tree. There's an online editor such as this: jsoneditoronline.org, but that's really just a small step beyond notepad text editor. Would be nice if there was a way to add some auto-checking and auto-populating of parameters with default values.