com.google.gson.internal.bind.JsonTreeReader Java Examples

The following examples show how to use com.google.gson.internal.bind.JsonTreeReader. 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: gson   Author: google   File: JsonReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void promoteNameToValue(JsonReader reader) throws IOException {
  if (reader instanceof JsonTreeReader) {
    ((JsonTreeReader)reader).promoteNameToValue();
    return;
  }
  int p = reader.peeked;
  if (p == PEEKED_NONE) {
    p = reader.doPeek();
  }
  if (p == PEEKED_DOUBLE_QUOTED_NAME) {
    reader.peeked = PEEKED_DOUBLE_QUOTED;
  } else if (p == PEEKED_SINGLE_QUOTED_NAME) {
    reader.peeked = PEEKED_SINGLE_QUOTED;
  } else if (p == PEEKED_UNQUOTED_NAME) {
    reader.peeked = PEEKED_UNQUOTED;
  } else {
    throw new IllegalStateException(
        "Expected a name but was " + reader.peek() + reader.locationString());
  }
}
 
Example #2
Source Project: framework   Author: Odoo-mobile   File: JsonReader.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override public void promoteNameToValue(JsonReader reader) throws IOException {
  if (reader instanceof JsonTreeReader) {
    ((JsonTreeReader)reader).promoteNameToValue();
    return;
  }
  int p = reader.peeked;
  if (p == PEEKED_NONE) {
    p = reader.doPeek();
  }
  if (p == PEEKED_DOUBLE_QUOTED_NAME) {
    reader.peeked = PEEKED_DOUBLE_QUOTED;
  } else if (p == PEEKED_SINGLE_QUOTED_NAME) {
    reader.peeked = PEEKED_SINGLE_QUOTED;
  } else if (p == PEEKED_UNQUOTED_NAME) {
    reader.peeked = PEEKED_UNQUOTED;
  } else {
    throw new IllegalStateException("Expected a name but was " + reader.peek() + " "
        + " at line " + reader.getLineNumber() + " column " + reader.getColumnNumber()
        + " path " + reader.getPath());
  }
}
 
Example #3
Source Project: letv   Author: JackChan1999   File: JsonReader.java    License: Apache License 2.0 5 votes vote down vote up
public void promoteNameToValue(JsonReader reader) throws IOException {
    if (reader instanceof JsonTreeReader) {
        ((JsonTreeReader) reader).promoteNameToValue();
        return;
    }
    reader.peek();
    if (reader.token != JsonToken.NAME) {
        throw new IllegalStateException("Expected a name but was " + reader.peek() + " " + " at line " + reader.getLineNumber() + " column " + reader.getColumnNumber());
    }
    reader.value = reader.name;
    reader.name = null;
    reader.token = JsonToken.STRING;
}
 
Example #4
Source Project: letv   Author: JackChan1999   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
final T fromJsonTree(JsonElement jsonTree) {
    try {
        JsonReader jsonReader = new JsonTreeReader(jsonTree);
        jsonReader.setLenient(true);
        return read(jsonReader);
    } catch (Throwable e) {
        throw new JsonIOException(e);
    }
}
 
Example #5
Source Project: MiBandDecompiled   Author: vishnudevk   File: a.java    License: Apache License 2.0 5 votes vote down vote up
public void promoteNameToValue(JsonReader jsonreader)
{
    if (jsonreader instanceof JsonTreeReader)
    {
        ((JsonTreeReader)jsonreader).promoteNameToValue();
        return;
    }
    int i = JsonReader.a(jsonreader);
    if (i == 0)
    {
        i = JsonReader.b(jsonreader);
    }
    if (i == 13)
    {
        JsonReader.a(jsonreader, 9);
        return;
    }
    if (i == 12)
    {
        JsonReader.a(jsonreader, 8);
        return;
    }
    if (i == 14)
    {
        JsonReader.a(jsonreader, 10);
        return;
    } else
    {
        throw new IllegalStateException((new StringBuilder()).append("Expected a name but was ").append(jsonreader.peek()).append(" ").append(" at line ").append(JsonReader.c(jsonreader)).append(" column ").append(JsonReader.d(jsonreader)).toString());
    }
}
 
Example #6
Source Project: MiBandDecompiled   Author: vishnudevk   File: Gson.java    License: Apache License 2.0 5 votes vote down vote up
public Object fromJson(JsonElement jsonelement, Type type)
{
    if (jsonelement == null)
    {
        return null;
    } else
    {
        return fromJson(((JsonReader) (new JsonTreeReader(jsonelement))), type);
    }
}
 
Example #7
Source Project: MiBandDecompiled   Author: vishnudevk   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public final Object fromJsonTree(JsonElement jsonelement)
{
    Object obj;
    try
    {
        obj = read(new JsonTreeReader(jsonelement));
    }
    catch (IOException ioexception)
    {
        throw new JsonIOException(ioexception);
    }
    return obj;
}
 
Example #8
Source Project: gson   Author: google   File: TypeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts {@code jsonTree} to a Java object.
 *
 * @param jsonTree the Java object to convert. May be {@link JsonNull}.
 * @since 2.2
 */
public final T fromJsonTree(JsonElement jsonTree) {
  try {
    JsonReader jsonReader = new JsonTreeReader(jsonTree);
    return read(jsonReader);
  } catch (IOException e) {
    throw new JsonIOException(e);
  }
}
 
Example #9
Source Project: framework   Author: Odoo-mobile   File: TypeAdapter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Converts {@code jsonTree} to a Java object.
 *
 * @param jsonTree the Java object to convert. May be {@link JsonNull}.
 * @since 2.2
 */
public final T fromJsonTree(JsonElement jsonTree) {
  try {
    JsonReader jsonReader = new JsonTreeReader(jsonTree);
    return read(jsonReader);
  } catch (IOException e) {
    throw new JsonIOException(e);
  }
}
 
Example #10
Source Project: letv   Author: JackChan1999   File: Gson.java    License: Apache License 2.0 4 votes vote down vote up
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
    if (json == null) {
        return null;
    }
    return fromJson(new JsonTreeReader(json), typeOfT);
}
 
Example #11
Source Project: gson   Author: google   File: JsonReaderPathTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override public JsonReader create(String data) {
  JsonElement element = Streams.parse(new JsonReader(new StringReader(data)));
  return new JsonTreeReader(element);
}
 
Example #12
Source Project: immutables   Author: immutables   File: ExpectedSubtypesAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public JsonReader create() {
  return new JsonTreeReader(element);
}
 
Example #13
Source Project: gson   Author: google   File: Gson.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * This method deserializes the Json read from the specified parse tree into an object of the
 * specified type. This method is useful if the specified object is a generic type. For
 * non-generic objects, use {@link #fromJson(JsonElement, Class)} instead.
 *
 * @param <T> the type of the desired object
 * @param json the root of the parse tree of {@link JsonElement}s from which the object is to
 * be deserialized
 * @param typeOfT 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 typeOfT = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
 * </pre>
 * @return an object of type T from the json. Returns {@code null} if {@code json} is {@code null}
 * or if {@code json} is empty.
 * @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT
 * @since 1.3
 */
@SuppressWarnings("unchecked")
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
  if (json == null) {
    return null;
  }
  return (T) fromJson(new JsonTreeReader(json), typeOfT);
}
 
Example #14
Source Project: framework   Author: Odoo-mobile   File: Gson.java    License: GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * This method deserializes the Json read from the specified parse tree into an object of the
 * specified type. This method is useful if the specified object is a generic type. For
 * non-generic objects, use {@link #fromJson(JsonElement, Class)} instead.
 *
 * @param <T> the type of the desired object
 * @param json the root of the parse tree of {@link JsonElement}s from which the object is to
 * be deserialized
 * @param typeOfT 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 typeOfT = new TypeToken&lt;Collection&lt;Foo&gt;&gt;(){}.getType();
 * </pre>
 * @return an object of type T from the json. Returns {@code null} if {@code json} is {@code null}.
 * @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT
 * @since 1.3
 */
@SuppressWarnings("unchecked")
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
  if (json == null) {
    return null;
  }
  return (T) fromJson(new JsonTreeReader(json), typeOfT);
}