本文整理汇总了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());
}
}
};
}
示例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());
}
};
}
示例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);
}
};
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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();
}
示例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;
}