Package com.google.gson.stream

Examples of com.google.gson.stream.JsonWriter


  public String toString()
  {
    try
    {
      StringWriter localStringWriter = new StringWriter();
      JsonWriter localJsonWriter = new JsonWriter(localStringWriter);
      localJsonWriter.setLenient(true);
      Streams.write(this, localJsonWriter);
      return localStringWriter.toString();
    }
    catch (IOException localIOException)
    {
View Full Code Here


     
      // Attempt to serialize event atomically to a top-level value.
      // See GH-92 for more info.
      final StringWriter sw = new StringWriter();
      try {
        final JsonWriter jsonWriter = new JsonWriter(sw);
        jsonWriter.setIndent("  ");
        jsonWriter.beginArray();
        jsonWriter.value(event.getType().name());
        gson.toJson(event, event.getClass(), jsonWriter);
        jsonWriter.endArray();
        jsonWriter.close();
      } catch (Throwable t) {
        SlaveMain.warn("Unhandled exception in event serialization.", t);
        Rethrow.rethrow(t); // or skip?
      }
View Full Code Here

  private JsonWriter writer;
  private Gson gson;

  public Serializer(OutputStream os) throws IOException {
    this.writer = new JsonWriter(new OutputStreamWriter(os, Charsets.UTF_8));
    this.writer.setIndent("  ");
    this.writer.beginArray();

    this.gson = createGSon(Thread.currentThread().getContextClassLoader());
  }
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

  /// <returns></returns>
  public static String SerializeLLSDJsonString(OSD data) throws Exception
  {

    StringWriter swriter = new StringWriter();
    JsonWriter jwriter = new JsonWriter(swriter);
       jwriter.setIndent(" ");
    jwriter.beginArray();
   
    SerializeLLSDJsonElement(jwriter, data);
   
    jwriter.endArray();
   
    return swriter.getBuffer().toString();   
  }
View Full Code Here

      OSDMap map = (OSDMap)data;

      doc.beginObject();
      for(Map.Entry<String, OSD> entry: map.entrySet())
      {
        JsonWriter tempWriter = doc.name(entry.getKey());
       
        SerializeLLSDJsonElement(tempWriter, entry.getValue());       
      }     
      doc.endObject();
     
View Full Code Here

   * @param context the serialization context
   */
  public void write(T object, SerializationContext context) {
    context.pushPath("(" + simpleName + ".write())");
    try {
      JsonWriter writer = context.getWriter();
      if (object == null) {
        writer.nullValue();
      } else {
        writeNotNull(object, context);
      }
    } catch (Exception e) {
      context.fail(e);
View Full Code Here

    return clazz.getCanonicalName();
  }

  @Override
  public void writeNotNull(T object, SerializationContext context) throws IOException {
    JsonWriter writer = context.getWriter();
    writer.value(object.getUuid().toString());
  }
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.