Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java EE 7 Json.createBuilderFactory(config) - what can you do with a non-null config?

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)

like image 871
Bradley Slavik Avatar asked Sep 09 '14 19:09

Bradley Slavik


1 Answers

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);
like image 177
shudong Avatar answered Nov 01 '22 11:11

shudong