当前位置: 首页>>代码示例>>Java>>正文


Java JsonReader.nextNull方法代码示例

本文整理汇总了Java中com.google.gson.stream.JsonReader.nextNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.nextNull方法的具体用法?Java JsonReader.nextNull怎么用?Java JsonReader.nextNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.stream.JsonReader的用法示例。


在下文中一共展示了JsonReader.nextNull方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: longAdapter

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) {
  if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) {
    return TypeAdapters.LONG;
  }
  return new TypeAdapter<Number>() {
    @Override public Number read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }
      return in.nextLong();
    }
    @Override public void write(JsonWriter out, Number value) throws IOException {
      if (value == null) {
        out.nullValue();
        return;
      }
      out.value(value.toString());
    }
  };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:Gson.java

示例2: longAdapter

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) {
    if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) {
        return TypeAdapters.LONG;
    }
    return new TypeAdapter<Number>() {
        public Number read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Long.valueOf(in.nextLong());
            }
            in.nextNull();
            return null;
        }

        public void write(JsonWriter out, Number value) throws IOException {
            if (value == null) {
                out.nullValue();
            } else {
                out.value(value.toString());
            }
        }
    };
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:Gson.java

示例3: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Locale read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  String locale = in.nextString();
  StringTokenizer tokenizer = new StringTokenizer(locale, "_");
  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);
  } else if (variant == null) {
    return new Locale(language, country);
  } else {
    return new Locale(language, country, variant);
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:29,代码来源:TypeAdapters.java

示例4: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Calendar read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return  null;
  }
  in.beginObject();
  int year = 0;
  int month = 0;
  int dayOfMonth = 0;
  int hourOfDay = 0;
  int minute = 0;
  int second = 0;
  while (in.peek() != JsonToken.END_OBJECT) {
    String name = in.nextName();
    int value = in.nextInt();
    if (YEAR.equals(name)) {
      year = value;
    } else if (MONTH.equals(name)) {
      month = value;
    } else if (DAY_OF_MONTH.equals(name)) {
      dayOfMonth = value;
    } else if (HOUR_OF_DAY.equals(name)) {
      hourOfDay = value;
    } else if (MINUTE.equals(name)) {
      minute = value;
    } else if (SECOND.equals(name)) {
      second = value;
    }
  }
  in.endObject();
  return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:TypeAdapters.java

示例5: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public JsonElement read(JsonReader in) throws IOException {
    switch (in.peek()) {
        case NUMBER:
            return new JsonPrimitive(new LazilyParsedNumber(in.nextString()));
        case BOOLEAN:
            return new JsonPrimitive(Boolean.valueOf(in.nextBoolean()));
        case STRING:
            return new JsonPrimitive(in.nextString());
        case NULL:
            in.nextNull();
            return JsonNull.INSTANCE;
        case BEGIN_ARRAY:
            JsonElement array = new JsonArray();
            in.beginArray();
            while (in.hasNext()) {
                array.add(read(in));
            }
            in.endArray();
            return array;
        case BEGIN_OBJECT:
            JsonElement object = new JsonObject();
            in.beginObject();
            while (in.hasNext()) {
                object.add(in.nextName(), read(in));
            }
            in.endObject();
            return object;
        default:
            throw new IllegalArgumentException();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:32,代码来源:TypeAdapters.java

示例6: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Object read(JsonReader in) throws IOException {
    JsonToken token = in.peek();
    switch (token) {
        case BEGIN_ARRAY:
            List<Object> list = new ArrayList<>();
            in.beginArray();
            while (in.hasNext()) {
                list.add(read(in));
            }
            in.endArray();
            return list;
        case BEGIN_OBJECT:
            Map<String, Object> map = new LinkedTreeMap<>();
            in.beginObject();
            while (in.hasNext()) {
                map.put(in.nextName(), read(in));
            }
            in.endObject();
            return map;
        case STRING:
            return in.nextString();
        case NUMBER:
            return getNumber(in.nextString());
        case BOOLEAN:
            return in.nextBoolean();
        case NULL:
            in.nextNull();
            return null;
        default:
            throw new IllegalStateException();
    }
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:34,代码来源:NumberPredictObjectTypeAdapterFactory.java

示例7: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public DateTime read(JsonReader in) throws IOException {
  switch (in.peek()) {
    case NULL:
      in.nextNull();
      return null;
    default:
      String date = in.nextString();
      return parseFormatter.parseDateTime(date);
  }
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:12,代码来源:ApiClient.java

示例8: read

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Object read(JsonReader in) throws IOException {
    switch (in.peek()) {
        case BEGIN_ARRAY:
            List<Object> list = new ArrayList();
            in.beginArray();
            while (in.hasNext()) {
                list.add(read(in));
            }
            in.endArray();
            return list;
        case BEGIN_OBJECT:
            Map<String, Object> map = new LinkedHashMap();
            in.beginObject();
            while (in.hasNext()) {
                map.put(in.nextName(), read(in));
            }
            in.endObject();
            return map;
        case STRING:
            return in.nextString();
        case NUMBER:
            return Double.valueOf(in.nextDouble());
        case BOOLEAN:
            return Boolean.valueOf(in.nextBoolean());
        case NULL:
            in.nextNull();
            return null;
        default:
            throw new IllegalStateException();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:32,代码来源:ObjectTypeAdapter.java

示例9: create

import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> TypeAdapter<T> create(Gson p_create_1_, TypeToken<T> p_create_2_)
{
    Class<T> oclass = (Class<T>)p_create_2_.getRawType();

    if (!oclass.isEnum())
    {
        return null;
    }
    else
    {
        final Map<String, T> map = Maps.<String, T>newHashMap();

        for (T t : oclass.getEnumConstants())
        {
            map.put(this.func_151232_a(t), t);
        }

        return new TypeAdapter<T>()
        {
            public void write(JsonWriter p_write_1_, T p_write_2_) throws IOException
            {
                if (p_write_2_ == null)
                {
                    p_write_1_.nullValue();
                }
                else
                {
                    p_write_1_.value(EnumTypeAdapterFactory.this.func_151232_a(p_write_2_));
                }
            }
            public T read(JsonReader p_read_1_) throws IOException
            {
                if (p_read_1_.peek() == JsonToken.NULL)
                {
                    p_read_1_.nextNull();
                    return (T)null;
                }
                else
                {
                    return (T)map.get(p_read_1_.nextString());
                }
            }
        };
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:46,代码来源:EnumTypeAdapterFactory.java


注:本文中的com.google.gson.stream.JsonReader.nextNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。