com.google.gson.internal.JsonReaderInternalAccess Java Examples

The following examples show how to use com.google.gson.internal.JsonReaderInternalAccess. 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 File: MapTypeAdapterFactory.java    From letv with Apache License 2.0 5 votes vote down vote up
public Map<K, V> read(JsonReader in) throws IOException {
    JsonToken peek = in.peek();
    if (peek == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    Map<K, V> map = (Map) this.constructor.construct();
    K key;
    if (peek == JsonToken.BEGIN_ARRAY) {
        in.beginArray();
        while (in.hasNext()) {
            in.beginArray();
            key = this.keyTypeAdapter.read(in);
            if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
                throw new JsonSyntaxException("duplicate key: " + key);
            }
            in.endArray();
        }
        in.endArray();
        return map;
    }
    in.beginObject();
    while (in.hasNext()) {
        JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in);
        key = this.keyTypeAdapter.read(in);
        if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
            throw new JsonSyntaxException("duplicate key: " + key);
        }
    }
    in.endObject();
    return map;
}
 
Example #2
Source File: f.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public Map a(JsonReader jsonreader)
{
    JsonToken jsontoken = jsonreader.peek();
    if (jsontoken == JsonToken.NULL)
    {
        jsonreader.nextNull();
        return null;
    }
    Map map = (Map)d.construct();
    if (jsontoken == JsonToken.BEGIN_ARRAY)
    {
        jsonreader.beginArray();
        for (; jsonreader.hasNext(); jsonreader.endArray())
        {
            jsonreader.beginArray();
            Object obj1 = b.read(jsonreader);
            if (map.put(obj1, c.read(jsonreader)) != null)
            {
                throw new JsonSyntaxException((new StringBuilder()).append("duplicate key: ").append(obj1).toString());
            }
        }

        jsonreader.endArray();
        return map;
    }
    jsonreader.beginObject();
    while (jsonreader.hasNext()) 
    {
        JsonReaderInternalAccess.INSTANCE.promoteNameToValue(jsonreader);
        Object obj = b.read(jsonreader);
        if (map.put(obj, c.read(jsonreader)) != null)
        {
            throw new JsonSyntaxException((new StringBuilder()).append("duplicate key: ").append(obj).toString());
        }
    }
    jsonreader.endObject();
    return map;
}
 
Example #3
Source File: ProteusTypeAdapterFactory.java    From proteus with Apache License 2.0 5 votes vote down vote up
public Map<String, Value> readData(JsonReader in) throws IOException {
  JsonToken peek = in.peek();
  if (peek == JsonToken.NULL) {
    in.nextNull();
    return new HashMap<>();
  }

  if (peek != JsonToken.BEGIN_OBJECT) {
    throw new JsonSyntaxException("data must be a Map<String, String>.");
  }

  Map<String, Value> data = new LinkedHashMap<>();

  in.beginObject();
  while (in.hasNext()) {
    JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in);
    String key = in.nextString();
    Value value = VALUE_TYPE_ADAPTER.read(in);
    Value compiled = AttributeProcessor.staticPreCompile(value, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions);
    if (compiled != null) {
      value = compiled;
    }
    Value replaced = data.put(key, value);
    if (replaced != null) {
      throw new JsonSyntaxException("duplicate key: " + key);
    }
  }
  in.endObject();

  return data;
}