Package com.google.gson.stream

Examples of com.google.gson.stream.JsonWriter


public class BehaviorTreeLoader implements AssetLoader<BehaviorTreeData> {
    private static final Logger logger = LoggerFactory.getLogger(BehaviorTreeLoader.class);
    private BehaviorTreeGson treeGson = new BehaviorTreeGson();

    public void save(OutputStream stream, BehaviorTreeData data) throws IOException {
        try (JsonWriter write = new JsonWriter(new OutputStreamWriter(stream, Charsets.UTF_8))) {
            write.setIndent("  ");
            write.beginObject().name("model");
            treeGson.saveTree(write, data.getRoot());
            write.endObject();
        }
    }
View Full Code Here


   *
   * @param value the Java object to convert. May be null.
   * @since 2.2
   */
  public final void toJson(Writer out, T value) throws IOException {
    JsonWriter writer = new JsonWriter(out);
    write(writer, value);
  }
View Full Code Here

   */
  @Override
  public String toString() {
    try {
      StringWriter stringWriter = new StringWriter();
      JsonWriter jsonWriter = new JsonWriter(stringWriter);
      jsonWriter.setLenient(true);
      Streams.write(this, jsonWriter);
      return stringWriter.toString();
    } catch (IOException e) {
      throw new AssertionError(e);
    }
View Full Code Here

   * @throws JsonIOException if there was a problem writing to the writer
   * @since 1.2
   */
  public void toJson(Object src, Type typeOfSrc, Appendable writer) throws JsonIOException {
    try {
      JsonWriter jsonWriter = newJsonWriter(Streams.writerForAppendable(writer));
      toJson(src, typeOfSrc, jsonWriter);
    } catch (IOException e) {
      throw new JsonIOException(e);
    }
  }
View Full Code Here

   * @throws JsonIOException if there was a problem writing to the writer
   * @since 1.4
   */
  public void toJson(JsonElement jsonElement, Appendable writer) throws JsonIOException {
    try {
      JsonWriter jsonWriter = newJsonWriter(Streams.writerForAppendable(writer));
      toJson(jsonElement, jsonWriter);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

   */
  private JsonWriter newJsonWriter(Writer writer) throws IOException {
    if (generateNonExecutableJson) {
      writer.write(JSON_NON_EXECUTABLE_PREFIX);
    }
    JsonWriter jsonWriter = new JsonWriter(writer);
    if (prettyPrinting) {
      jsonWriter.setIndent("  ");
    }
    jsonWriter.setSerializeNulls(serializeNulls);
    return jsonWriter;
  }
View Full Code Here

public class GsonStreamTargetTest {
  @Test
  public void testObjectValue() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startObject();
    target.name("alice");
    target.value("bob");
    target.endObject();
View Full Code Here

  }

  @Test
  public void testArrayValue() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startArray();
    target.value("bob");
    target.endArray();
   
View Full Code Here

  }

  @Test
  public void testArray1() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startObject();
    target.name("alice");
    target.startArray();
    target.value("bob");
View Full Code Here

  }

  @Test
  public void testArray2() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startObject();
    target.name("alice");
    target.startObject();
    target.name("bob");
View Full Code Here

TOP

Related Classes of com.google.gson.stream.JsonWriter

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.