Package com.google.gson.stream

Examples of com.google.gson.stream.JsonWriter


    }
  }

  private JsonWriter getJsonWriter(ClassDoc clazz) throws IOException {
    PackageDoc pkg = clazz.containingPackage();
    JsonWriter toReturn = writersByPackage.get(pkg);
    if (toReturn == null) {
      toReturn = new JsonWriter(openWriter(pkg.name().replace('.', '/') + "/package.json"));
      toReturn.setIndent("  ");
      writersByPackage.put(pkg, toReturn);

      toReturn.beginObject();
    }
    return toReturn;
  }
View Full Code Here


    return toReturn;
  }

  @Override
  public void writeNotNull(Object object, SerializationContext context) throws Exception {
    JsonWriter writer = context.getWriter();
    writer.beginArray();
    for (int i = 0, j = Array.getLength(object); i < j; i++) {
      context.pushPath("[" + i + "]");
      valueCodex.write(boxedType.cast(Array.get(object, i)), context);
      context.popPath();
    }
    writer.endArray();
  }
View Full Code Here

    return oldValue;
  }

  @Override
  public void writeNotNull(T collection, SerializationContext context) throws IOException {
    JsonWriter writer = context.getWriter();
    writer.beginArray();
    int count = 0;
    for (V t : collection) {
      context.pushPath("[" + count++ + "]");
      valueCodex.write(t, context);
      context.popPath();
    }
    writer.endArray();
  }
View Full Code Here

    return toReturn;
  }

  @Override
  public void writeNotNull(T[] object, SerializationContext context) throws IOException {
    JsonWriter writer = context.getWriter();
    writer.beginArray();
    int count = 0;
    for (T t : object) {
      context.pushPath("[" + count++ + "]");
      valueCodex.write(t, context);
      context.popPath();
    }
    writer.endArray();
  }
View Full Code Here

   * @throws IOException error writing to the {@code OutputStream}
   */
  public static <T> void writeObjectsToStreamAsJson(Gson gson, OutputStream out, List<T> list)
      throws IOException {

    JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
    writer.setIndent("  ");
    writer.beginArray();
    for (T t : list) {
      gson.toJson(t, t.getClass(), writer);
    }
    writer.endArray();
    writer.close();
  }
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.