當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。