Package com.google.gson.stream

Examples of com.google.gson.stream.JsonWriter


  }

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


  }

  @Test
  public void testString() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startArray();
    target.value("");
    target.value("abc");
    target.value("\b\f\n\r\t");
View Full Code Here

  }

  @Test
  public void testSimpleValue() throws IOException {
    StringWriter writer = new StringWriter();
    GsonStreamTarget target = new GsonStreamTarget(new JsonWriter(writer));
   
    target.startArray();
    target.value("abc");
    target.value(1234);
    target.value(true);
View Full Code Here

    return createJsonStreamTarget(new OutputStreamWriter(output), pretty);
  }
 
  @Override
  public JsonStreamTarget createJsonStreamTarget(Writer writer, boolean pretty) {
    JsonWriter jsonWriter = new JsonWriter(new FilterWriter(writer) {
      @Override
      public void close() throws IOException {
        flush(); // avoid closing underlying stream
      }
    });
    jsonWriter.setLenient(false);
    jsonWriter.setIndent(pretty ? "\t" : "");
    return new GsonStreamTarget(jsonWriter);
  }
View Full Code Here

        writeEnergyValueStackMapToJsonFile(getFileInDataDirectory(fileName), energyValueMap);
    }

    public static void writeEnergyValueStackMapToJsonFile(File jsonFile, Map<WrappedStack, EnergyValue> energyValueMap)
    {
        JsonWriter jsonWriter;

        try
        {
            jsonWriter = new JsonWriter(new FileWriter(jsonFile));
            jsonWriter.setIndent("    ");
            jsonWriter.beginArray();
            for (WrappedStack wrappedStack : energyValueMap.keySet())
            {
                jsonSerializer.toJson(new EnergyValueStackMapping(wrappedStack, energyValueMap.get(wrappedStack)), EnergyValueStackMapping.class, jsonWriter);
            }

            jsonWriter.endArray();
            jsonWriter.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
View Full Code Here

   * @param file writer to write to. Will be closed after writing is finished
   * @param t    type of object
   * @throws IOException if writing fails
   */
  public static void toFile(Object o, Writer file, Type t) throws IOException{
    JsonWriter writer = new JsonWriter(file);
    gson.toJson(o, t, writer);
    writer.close();
  }
View Full Code Here

  public void toJson(Object paramObject, Type paramType, Appendable paramAppendable)
    throws JsonIOException
  {
    try
    {
      JsonWriter localJsonWriter = newJsonWriter(Streams.writerForAppendable(paramAppendable));
      toJson(paramObject, paramType, localJsonWriter);
    }
    catch (IOException localIOException)
    {
      throw new JsonIOException(localIOException);
View Full Code Here

  public void toJson(JsonElement paramJsonElement, Appendable paramAppendable)
    throws JsonIOException
  {
    try
    {
      JsonWriter localJsonWriter = newJsonWriter(Streams.writerForAppendable(paramAppendable));
      toJson(paramJsonElement, localJsonWriter);
    }
    catch (IOException localIOException)
    {
      throw new RuntimeException(localIOException);
View Full Code Here

  private JsonWriter newJsonWriter(Writer paramWriter)
    throws IOException
  {
    if (this.generateNonExecutableJson)
      paramWriter.write(")]}'\n");
    JsonWriter localJsonWriter = new JsonWriter(paramWriter);
    if (this.prettyPrinting)
      localJsonWriter.setIndent("  ");
    localJsonWriter.setSerializeNulls(this.serializeNulls);
    return localJsonWriter;
  }
View Full Code Here

    throws IOException;

  public final void toJson(Writer paramWriter, Object paramObject)
    throws IOException
  {
    JsonWriter localJsonWriter = new JsonWriter(paramWriter);
    write(localJsonWriter, paramObject);
  }
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.