Java Code Examples for com.google.gson.internal.bind.JsonTreeWriter#get()

The following examples show how to use com.google.gson.internal.bind.JsonTreeWriter#get() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: letv   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
final JsonElement toJsonTree(T value) {
    try {
        JsonTreeWriter jsonWriter = new JsonTreeWriter();
        jsonWriter.setLenient(true);
        write(jsonWriter, value);
        return jsonWriter.get();
    } catch (Throwable e) {
        throw new JsonIOException(e);
    }
}
 
Example 2
Source Project: MiBandDecompiled   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public final JsonElement toJsonTree(Object obj)
{
    JsonElement jsonelement;
    try
    {
        JsonTreeWriter jsontreewriter = new JsonTreeWriter();
        write(jsontreewriter, obj);
        jsonelement = jsontreewriter.get();
    }
    catch (IOException ioexception)
    {
        throw new JsonIOException(ioexception);
    }
    return jsonelement;
}
 
Example 3
Source Project: gson   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts {@code value} to a JSON tree.
 *
 * @param value the Java object to convert. May be null.
 * @return the converted JSON tree. May be {@link JsonNull}.
 * @since 2.2
 */
public final JsonElement toJsonTree(T value) {
  try {
    JsonTreeWriter jsonWriter = new JsonTreeWriter();
    write(jsonWriter, value);
    return jsonWriter.get();
  } catch (IOException e) {
    throw new JsonIOException(e);
  }
}
 
Example 4
/**
 * Converts {@code value} to a JSON tree.
 *
 * @param value the Java object to convert. May be null.
 * @return the converted JSON tree. May be {@link JsonNull}.
 * @since 2.2
 */
public final JsonElement toJsonTree(T value) {
  try {
    JsonTreeWriter jsonWriter = new JsonTreeWriter();
    write(jsonWriter, value);
    return jsonWriter.get();
  } catch (IOException e) {
    throw new JsonIOException(e);
  }
}
 
Example 5
protected JsonElement toTree(JsonReader in) throws IOException {
	JsonTreeWriter writer = new JsonTreeWriter();
	transfer(in, writer);
	return writer.get();
}
 
Example 6
Source Project: MiBandDecompiled   File: Gson.java    License: Apache License 2.0 4 votes vote down vote up
public JsonElement toJsonTree(Object obj, Type type)
{
    JsonTreeWriter jsontreewriter = new JsonTreeWriter();
    toJson(obj, type, jsontreewriter);
    return jsontreewriter.get();
}
 
Example 7
Source Project: gson   File: Gson.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * This method serializes the specified object, including those of generic types, into its
 * equivalent representation as a tree of {@link JsonElement}s. This method must be used if the
 * specified object is a generic type. For non-generic objects, use {@link #toJsonTree(Object)}
 * instead.
 *
 * @param src the object for which JSON representation is to be created
 * @param typeOfSrc The specific genericized type of src. You can obtain
 * this type by using the {@link com.google.gson.reflect.TypeToken} class. For example,
 * to get the type for {@code Collection<Foo>}, you should use:
 * <pre>
 * Type typeOfSrc = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
 * </pre>
 * @return Json representation of {@code src}
 * @since 1.4
 */
public JsonElement toJsonTree(Object src, Type typeOfSrc) {
  JsonTreeWriter writer = new JsonTreeWriter();
  toJson(src, typeOfSrc, writer);
  return writer.get();
}
 
Example 8
/**
 * This method serializes the specified object, including those of generic types, into its
 * equivalent representation as a tree of {@link JsonElement}s. This method must be used if the
 * specified object is a generic type. For non-generic objects, use {@link #toJsonTree(Object)}
 * instead.
 *
 * @param src the object for which JSON representation is to be created
 * @param typeOfSrc The specific genericized type of src. You can obtain
 * this type by using the {@link TypeToken} class. For example,
 * to get the type for {@code Collection<Foo>}, you should use:
 * <pre>
 * Type typeOfSrc = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
 * </pre>
 * @return Json representation of {@code src}
 * @since 1.4
 */
public JsonElement toJsonTree(Object src, Type typeOfSrc) {
  JsonTreeWriter writer = new JsonTreeWriter();
  toJson(src, typeOfSrc, writer);
  return writer.get();
}