I was trying to use the Java EE 7 JsonBuilder and have been having trouble understanding the config parameter for createBuilderFactory. Yes, one can leave it blank or null, but what else can one do?
JsonBuilderFactory factory = Json.createBuilderFactory(config);
JsonObject value = factory.createObjectBuilder()
.add("firstName", "John")
.add("lastName", "Smith")
.add("age", 25).build();
What can one do with config? Spacing around colons or commas? Line breaks for each array? I don't know how to look at the source code, and it does not appear to be documented at the Java EE page for json (http://docs.oracle.com/javaee/7/api/index.html?javax/json/Json.html)
I think it really depends on the Java EE 7 implementation. For Glass Fish, you could just pass null for Json.createXXXFactory() methods, except for Json.createWriterFactory/createGeneratorFactory() method which you could pass configuration option whether to do pretty printing or not.
Map<String, Object> config = new HashMap<String, Object>();
//if you need pretty printing
config.put("javax.json.stream.JsonGenerator.prettyPrinting", Boolean.valueOf(true));
JsonWriterFactory factory = Json.createWriterFactory(config);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With