當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonToken類代碼示例

本文整理匯總了Java中com.google.gson.stream.JsonToken的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken類的具體用法?Java JsonToken怎麽用?Java JsonToken使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonToken類屬於com.google.gson.stream包,在下文中一共展示了JsonToken類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public T read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    T instance = this.constructor.construct();
    try {
        in.beginObject();
        while (in.hasNext()) {
            BoundField field = (BoundField) this.boundFields.get(in.nextName());
            if (field == null || !field.deserialized) {
                in.skipValue();
            } else {
                field.read(in, instance);
            }
        }
        in.endObject();
        return instance;
    } catch (Throwable e) {
        throw new JsonSyntaxException(e);
    } catch (IllegalAccessException e2) {
        throw new AssertionError(e2);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:25,代碼來源:ReflectiveTypeAdapterFactory.java

示例2: floatAdapter

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
    if (serializeSpecialFloatingPointValues) {
        return TypeAdapters.FLOAT;
    }
    return new TypeAdapter<Number>() {
        public Float read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Float.valueOf((float) in.nextDouble());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
                return;
            }
            Gson.this.checkValidFloatingPoint((double) value.floatValue());
            out.value(value);
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:24,代碼來源:Gson.java

示例3: createJsonReader

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
/** Forces creation of more strict in string reading if in !lenient mode */
private JsonReader createJsonReader(Reader reader) {
  if (!options.lenient) {
    return new JsonReader(reader) {
      @Override
      public String nextString() throws IOException {
        JsonToken peeked = peek();
        if (peeked == JsonToken.STRING) {
          return super.nextString();
        }
        throw new JsonParseException(
            String.format("In strict mode (!lenient) string read only from string literal, not %s. Path: %s",
                peeked,
                getPath()));
      }
    };
  }
  return new JsonReader(reader);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:GsonMessageBodyProvider.java

示例4: nullSafe

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public final TypeAdapter<T> nullSafe() {
    return new TypeAdapter<T>() {
        public void write(JsonWriter out, T value) throws IOException {
            if (value == null) {
                out.nullValue();
            } else {
                TypeAdapter.this.write(out, value);
            }
        }

        public T read(JsonReader reader) throws IOException {
            if (reader.peek() != JsonToken.NULL) {
                return TypeAdapter.this.read(reader);
            }
            reader.nextNull();
            return null;
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:TypeAdapter.java

示例5: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public Object read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    List<E> list = new ArrayList();
    in.beginArray();
    while (in.hasNext()) {
        list.add(this.componentTypeAdapter.read(in));
    }
    in.endArray();
    Object array = Array.newInstance(this.componentType, list.size());
    for (int i = 0; i < list.size(); i++) {
        Array.set(array, i, list.get(i));
    }
    return array;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:ArrayTypeAdapter.java

示例6: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public Locale read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    StringTokenizer tokenizer = new StringTokenizer(in.nextString(), EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR);
    String language = null;
    String country = null;
    String variant = null;
    if (tokenizer.hasMoreElements()) {
        language = tokenizer.nextToken();
    }
    if (tokenizer.hasMoreElements()) {
        country = tokenizer.nextToken();
    }
    if (tokenizer.hasMoreElements()) {
        variant = tokenizer.nextToken();
    }
    if (country == null && variant == null) {
        return new Locale(language);
    }
    if (variant == null) {
        return new Locale(language, country);
    }
    return new Locale(language, country, variant);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:27,代碼來源:TypeAdapters.java

示例7: floatAdapter

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) {
  if (serializeSpecialFloatingPointValues) {
    return TypeAdapters.FLOAT;
  }
  return new TypeAdapter<Number>() {
    @Override public Float read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return (float) in.nextDouble();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      float floatValue = value.floatValue();
      checkValidFloatingPoint(floatValue);
      out.value(value);
    }
  };
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:Gson.java

示例8: parse

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
    try {
        JsonReader jsonReader = new JsonReader(json);
        JsonElement element = parse(jsonReader);
        if (element.isJsonNull() || jsonReader.peek() == JsonToken.END_DOCUMENT) {
            return element;
        }
        throw new JsonSyntaxException("Did not consume the entire document.");
    } catch (Throwable e) {
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonIOException(e2);
    } catch (Throwable e22) {
        throw new JsonSyntaxException(e22);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:JsonParser.java

示例9: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
@Override public AnInterface read(JsonReader jsonReader) throws IOException {
  jsonReader.beginObject();

  String name = null;
  while (jsonReader.peek() != JsonToken.END_OBJECT) {
    switch (jsonReader.nextName()) {
      case "name":
        name = jsonReader.nextString();
        break;
    }
  }

  jsonReader.endObject();
  return new AnImplementation(name);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:GsonConverterFactoryTest.java

示例10: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
@Override
public StringBuilder read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  return new StringBuilder(in.nextString());
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:9,代碼來源:TypeAdapters.java

示例11: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public InetAddress read(JsonReader in) throws IOException {
    if (in.peek() != JsonToken.NULL) {
        return InetAddress.getByName(in.nextString());
    }
    in.nextNull();
    return null;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:TypeAdapters.java

示例12: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
@Override
public T read(
    final JsonReader in
) throws IOException {

  // support null objects
  if (in.peek() == JsonToken.NULL) {
    // consume object
    in.nextNull();

    // return null
    return null;
  }

  try {
    // try to read union
    return readUnion(in);

  } catch (Exception e) {
    // skip remaining values
    while (in.hasNext()) {
      in.skipValue();
    }

    // assert end of object
    in.endObject();

    // we failed in converting the union
    return null;
  }
}
 
開發者ID:aguther,項目名稱:dds-examples,代碼行數:32,代碼來源:UnionTypeAdapterFactory.java

示例13: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
public String read(JsonReader reader) {
    try {

        if (reader.peek() == JsonToken.NULL) {
            reader.nextNull();
            return "";//原先是返回Null,這裏改為返回空字符串
        }
        return reader.nextString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
 
開發者ID:forplane,項目名稱:retro2call,代碼行數:14,代碼來源:CommonJson4List.java

示例14: read

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
@Override
public Number read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  return (float) in.nextDouble();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:TypeAdapters.java

示例15: deserialize

import com.google.gson.stream.JsonToken; //導入依賴的package包/類
@Override
public void deserialize(JsonReader reader) throws IOException {
    reader.beginArray();
    while(reader.hasNext() && reader.peek().equals(JsonToken.STRING)) {
        String dim = reader.nextString();
        for(DimensionType type : DimensionType.values()) if(Objects.equals(type.getName(), dim)) {
            add(type);
            break;
        }
    }
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:12,代碼來源:DimensionProperty.java


注:本文中的com.google.gson.stream.JsonToken類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。