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