当前位置: 首页>>代码示例>>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;未经允许,请勿转载。