Package javax.json.stream

Examples of javax.json.stream.JsonGeneratorFactory


            out.println("<title>Create JSON structures</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Generate JSON using JsonGeneratorFactory</h1>");
//            JsonGeneratorFactory factory = Json.createGeneratorFactory(new JsonConfiguration().withPrettyPrinting());
            JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
//            JsonGenerator gen = factory.createGenerator(System.out);

            out.println("Creating an empty object ...<br>");
            JsonGenerator gen = factory.createGenerator(out);
//            JsonGenerator gen = Json.createGenerator(out);
            gen.writeStartObject().writeEnd();
            gen.flush();
            out.println("<br>...done<br>");

            out.println("<br>Creating a simple object ...<br>");
            gen = factory.createGenerator(out);
            gen
                    .writeStartObject()
                    .write("apple", "red")
                    .write("banana", "yellow")
                    .writeEnd();
            gen.flush();
            out.println("<br>...done<br>");

            out.println("<br>Creating a simple array ...<br>");
            gen = factory.createGenerator(out);
            gen
                    .writeStartArray()
                    .writeStartObject()
                    .write("apple", "red")
                    .writeEnd()
                    .writeStartObject()
                    .write("banana", "yellow")
                    .writeEnd()
                    .writeEnd();
            gen.flush();
            out.println("<br>...done<br>");

            out.println("<br>Creating a nested structure ...<br>");
            gen = factory.createGenerator(out);
            gen
                    .writeStartObject()
                    .write("title", "The Matrix")
                    .write("year", 1999)
                    .writeStartArray("cast")
View Full Code Here


                .addAsLibraries(requiredLibraries);
    }

    @Test
    public void testEmptyObject() throws JSONException {
        JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
        StringWriter w = new StringWriter();
        JsonGenerator gen = factory.createGenerator(w);
        gen.writeStartObject().writeEnd();
        gen.flush();

        JSONAssert.assertEquals("{}", w.toString(), JSONCompareMode.STRICT);
    }
View Full Code Here

        JSONAssert.assertEquals("{}", w.toString(), JSONCompareMode.STRICT);
    }

    @Test
    public void testSimpleObject() throws JSONException {
        JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
        StringWriter w = new StringWriter();
        JsonGenerator gen = factory.createGenerator(w);

        gen
                .writeStartObject()
                .write("apple", "red")
                .write("banana", "yellow")
View Full Code Here

        JSONAssert.assertEquals("{\"apple\" : \"red\", \"banana\" : \"yellow\" }", w.toString(), JSONCompareMode.STRICT);
    }

    @Test
    public void testArray() throws JSONException {
        JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
        StringWriter w = new StringWriter();
        JsonGenerator gen = factory.createGenerator(w);

        gen
                .writeStartArray()
                .writeStartObject()
                .write("apple", "red")
View Full Code Here

        JSONAssert.assertEquals("[{\"apple\":\"red\"},{\"banana\":\"yellow\"}]", w.toString(), JSONCompareMode.STRICT);
    }

    @Test
    public void testNestedStructure() throws JSONException {
        JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
        StringWriter w = new StringWriter();
        JsonGenerator gen = factory.createGenerator(w);

        gen
                .writeStartObject()
                .write("title", "The Matrix")
                .write("year", 1999)
View Full Code Here

  private JsonGenerator createJsonGenerator(Writer theWriter) {
    Map<String, Object> properties = new HashMap<String, Object>(1);
    if (myPrettyPrint) {
      properties.put(JsonGenerator.PRETTY_PRINTING, myPrettyPrint);
    }
    JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    JsonGenerator eventWriter = jgf.createGenerator(theWriter);
    return eventWriter;
  }
View Full Code Here

  private JsonGenerator createJsonGenerator(Writer theWriter) {
    Map<String, Object> properties = new HashMap<String, Object>(1);
    if (myPrettyPrint) {
      properties.put(JsonGenerator.PRETTY_PRINTING, myPrettyPrint);
    }
    JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    JsonGenerator eventWriter = jgf.createGenerator(theWriter);
    return eventWriter;
  }
View Full Code Here

  private JsonGenerator createJsonGenerator(Writer theWriter) {
    Map<String, Object> properties = new HashMap<String, Object>(1);
    if (myPrettyPrint) {
      properties.put(JsonGenerator.PRETTY_PRINTING, myPrettyPrint);
    }
    JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    JsonGenerator eventWriter = jgf.createGenerator(theWriter);
    return eventWriter;
  }
View Full Code Here

  private JsonGenerator createJsonGenerator(Writer theWriter) {
    Map<String, Object> properties = new HashMap<String, Object>(1);
    if (myPrettyPrint) {
      properties.put(JsonGenerator.PRETTY_PRINTING, myPrettyPrint);
    }
    JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    JsonGenerator eventWriter = jgf.createGenerator(theWriter);
    return eventWriter;
  }
View Full Code Here

  private JsonGenerator createJsonGenerator(Writer theWriter) {
    Map<String, Object> properties = new HashMap<String, Object>(1);
    if (myPrettyPrint) {
      properties.put(JsonGenerator.PRETTY_PRINTING, myPrettyPrint);
    }
    JsonGeneratorFactory jgf = Json.createGeneratorFactory(properties);
    JsonGenerator eventWriter = jgf.createGenerator(theWriter);
    return eventWriter;
  }
View Full Code Here

TOP

Related Classes of javax.json.stream.JsonGeneratorFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.