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


Java JsonToken.NULL属性代码示例

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


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

示例1: longAdapter

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,项目名称:boohee_v5.6,代码行数:22,代码来源:Gson.java

示例2: longAdapter

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,代码行数:21,代码来源:Gson.java

示例3: doubleAdapter

private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
    if (serializeSpecialFloatingPointValues) {
        return TypeAdapters.DOUBLE;
    }
    return new TypeAdapter<Number>() {
        public Double read(JsonReader in) throws IOException {
            if (in.peek() != JsonToken.NULL) {
                return Double.valueOf(in.nextDouble());
            }
            in.nextNull();
            return null;
        }

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

示例4: read

public String read(JsonReader in) throws IOException {
    JsonToken peek = in.peek();
    if (peek == JsonToken.NULL) {
        in.nextNull();
        return null;
    } else if (peek == JsonToken.BOOLEAN) {
        return Boolean.toString(in.nextBoolean());
    } else {
        return in.nextString();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:11,代码来源:TypeAdapters.java

示例5: read

public Collection<E> read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    Collection<E> collection = (Collection) this.constructor.construct();
    in.beginArray();
    while (in.hasNext()) {
        collection.add(this.elementTypeAdapter.read(in));
    }
    in.endArray();
    return collection;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:CollectionTypeAdapterFactory.java

示例6: read

@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,代码行数:28,代码来源:TypeAdapters.java

示例7: read

public BigInteger read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    try {
        return new BigInteger(in.nextString());
    } catch (Throwable e) {
        throw new JsonSyntaxException(e);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:TypeAdapters.java

示例8: read

@Override
public String read(JsonReader in) throws IOException {
  JsonToken peek = in.peek();
  if (peek == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  /* coerce booleans to strings for backwards compatibility */
  if (peek == JsonToken.BOOLEAN) {
    return Boolean.toString(in.nextBoolean());
  }
  return in.nextString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:TypeAdapters.java

示例9: read

@Override public synchronized Time read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }
  try {
    Date date = format.parse(in.nextString());
    return new Time(date.getTime());
  } catch (ParseException e) {
    throw new JsonSyntaxException(e);
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:12,代码来源:TimeTypeAdapter.java

示例10: read

@Override
public Optional<E> read(JsonReader in) throws IOException{
	if(in.peek() != JsonToken.NULL){
		return Optional.ofNullable(typeAdapter.read(in));
	}
	in.nextNull();
	return Optional.empty();
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:8,代码来源:OptionalTypeAdapterFactory.java

示例11: read

@Override
public ItemStack read(JsonReader in) throws IOException {
    Material material = null;
    Integer amount = null;
    Short dataValue = null;
    String name = null;
    List<String> lore = new ArrayList<>();
    Map<Enchantment, Integer> enchantments = new HashMap<>();

    if (in.peek() == JsonToken.NULL) {
        in.skipValue();
        return null;
    }

    in.beginObject();

    while (in.hasNext())
        switch (in.nextName()) {
            case MATERIAL:
                material = Material.getMaterial(in.nextString());
                break;
            case DATA_VALUE:
                dataValue = (short) in.nextInt();
                break;
            case AMOUNT:
                amount = in.nextInt();
                break;
            case LORE:
                in.beginArray();
                while (in.hasNext()) {
                    lore.add(in.nextString());
                }
                in.endArray();
                break;
            case NAME:
                name = in.nextString();
                break;
            case ENCHANTS:
                in.beginObject();
                while (in.hasNext())
                    enchantments.put(Enchantment.getByName(in.nextName()), in.nextInt());
                in.endObject();
                break;
    }

    if (material == null)
        throw new JsonParseException("An ItemStack must have a material field!");

    ItemStack stack = new ItemStack(material);
    if (amount != null) stack.setAmount(amount);
    if (dataValue != null) stack.setDurability(dataValue);
    if (name != null || !lore.isEmpty()) {
        ItemMeta itemMeta = stack.getItemMeta();
        if (name != null) itemMeta.setDisplayName(name);
        if (!lore.isEmpty()) itemMeta.setLore(lore);
        stack.setItemMeta(itemMeta);
    }
    if (!enchantments.isEmpty())
        for (Map.Entry<Enchantment, Integer> enchantmentIntegerEntry : enchantments.entrySet()) {
            stack.addUnsafeEnchantment(enchantmentIntegerEntry.getKey(), enchantmentIntegerEntry.getValue());
        }
    in.endObject();

    return stack;
}
 
开发者ID:Twister915,项目名称:pl,代码行数:65,代码来源:ItemStackTypeAdapter.java


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