本文整理汇总了Java中javax.json.Json.createGeneratorFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Json.createGeneratorFactory方法的具体用法?Java Json.createGeneratorFactory怎么用?Java Json.createGeneratorFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.Json
的用法示例。
在下文中一共展示了Json.createGeneratorFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonGeneratorFactory
import javax.json.Json; //导入方法依赖的package包/类
/**
* JsonGeneratorFactory getter with pretty printing on/off
* @param prettyPrintingif true, JSON will be pretty printed
* @return
*/
public static JsonGeneratorFactory getJsonGeneratorFactory(boolean prettyPrinting) {
Map<String, Object> properties = new HashMap<>(1);
if (prettyPrinting) {
// Putting any value sets the pretty printing to true... So test must be done
properties.put(JsonGenerator.PRETTY_PRINTING, prettyPrinting);
}
JsonGeneratorFactory jf = Json.createGeneratorFactory(properties);
return jf;
}
示例2: writeJsonStreamToString
import javax.json.Json; //导入方法依赖的package包/类
public static void writeJsonStreamToString(){
StringWriter stringWriter = new StringWriter();
JsonGeneratorFactory jsonGeneratorFactory = Json.createGeneratorFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
JsonGenerator generator = jsonGeneratorFactory.createGenerator(stringWriter);
generator.writeStartObject()
.write("title","JSON-Processing With Java EE")
.writeStartArray("chapters")
.write("Introduction")
.write("1. JSON and Java")
.write("2. JSON-Processing API features")
.write("3. The Java EE JSON Object model")
.write("4. The Java EE JSON Streaming model")
.write("Conclusion")
.writeEnd()
.write("released",JsonValue.TRUE)
.write("length",90)
.writeStartObject("sourceCode")
.write("repositoryName", "JSON-Processing-with-Java-EE")
.write("url","github.com/readlearncode")
.writeEnd()
.writeStartArray("complementaryCourse")
.writeStartObject()
.write("title", "RESTful Service with JAX-RS 2.0")
.write("length", 120)
.writeEnd()
.writeStartObject()
.write("title", "Java Enterprise Edition Introduction")
.write("length", 130)
.writeEnd()
.writeEnd()
.write("notes", JsonValue.NULL)
.writeEnd();
generator.close();
System.out.print(stringWriter.toString());
}
开发者ID:readlearncode,项目名称:JSON-Processing-with-Java-EE,代码行数:41,代码来源:StreamingExample3PrettyPrint.java