as the title suggest, I would like to create a Swing GUI based on a JSON Schema (that I fetch in real time) and use it to populate a JSONObject (Google SimpleJSON). I was thinking of using the Metawidget framework for this, but have been so far unsuccessful. I found various references online but none seem to be working for this particular case. There's always some classes or methods missing that are used in the example, and the documentation of Metawidget is not great (at least I wasn't able to find a set of examples for version 4.2). The JSON Schema I get describes Java classes that were described using Jackson's JSONSchema on the server side, but aren't available locally or can be known beforehand, so this should be handled as well.
Does anyone have any suggestions about a different approach, or some examples/references I can use? Of course, concrete code that compiles with Metawidget 4.2 is more that welcome as well.
--- EDIT --- (Due to the response of Richard Kennard)
Using the code blocks provided, I managed to generate a GUI. However, I needed to modify the value of the 'json' and 'jsonSchema' string and insert additional values, and switch the order of the inspectors passed to CompositeInspector. Here's the code and the generated GUI:
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
String json = "{\"person\": { \"firstname\": \"Richard\", \"surname\": \"Kennard\", \"notes\": \"Software developer\" }}";
String jsonSchema = "{ \"name\": \"person\", \"type\": \"person\", properties: { \"firstname\": { \"required\": true }, \"surname\": { \"required\": true }, \"notes\": { \"large\": true }}}";
final SwingMetawidget metawidget = new SwingMetawidget();
metawidget.setInspector( new CompositeInspector( new CompositeInspectorConfig().setInspectors(
new JsonSchemaInspector( new JsonInspectorConfig().setInputStream( new ByteArrayInputStream( jsonSchema.getBytes() ) ) ),
new JsonInspector( new JsonInspectorConfig().setInputStream( new ByteArrayInputStream( json.getBytes() ) ) )
)));
metawidget.setToInspect( json );
frame.add( metawidget, BorderLayout.CENTER );
frame.setSize(500, 500);
frame.setVisible(true);
This is without the usage of MapWidgetProcessor because (I suppose) it needs to be modified to support String to JSONObject conversion. (Also, the 'NAME' variable in that code block is undefined and supposedly needs to be replaced with 'elementName'?)
However, all of this begs a couple of new questions:
1) Why aren't the values from the 'json' mapped to the components?
2) What should the setup be if I didn't have the 'json' value, but only the 'jsonShema'?
3) Why doesn't the code work when explicitly specifying the property type in the schema like:
"firstname": { "required": true, "type": "string" }