本文整理汇总了Java中com.google.gson.stream.JsonToken.NAME属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.NAME属性的具体用法?Java JsonToken.NAME怎么用?Java JsonToken.NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.gson.stream.JsonToken
的用法示例。
在下文中一共展示了JsonToken.NAME属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: peek
@Override
public JsonToken peek() throws IOException {
JsonToken token = null;
if (state() == State.INITIAL || state() == State.SCOPE_DOCUMENT) {
advance();
token = toGsonToken(delegate.getCurrentBsonType());
} else if (state() == State.TYPE) {
advance();
token = toGsonToken(delegate.getCurrentBsonType());
} else if (state() == State.NAME) {
token = JsonToken.NAME;
} else if (state() == State.END_OF_DOCUMENT) {
token = JsonToken.END_OBJECT;
} else if (state() == State.END_OF_ARRAY) {
token = JsonToken.END_ARRAY;
} else if (state() == State.DONE) {
token = JsonToken.END_DOCUMENT;
} else if (state() == State.VALUE) {
token = toGsonToken(delegate.getCurrentBsonType());
}
if (token == null) {
throw new IllegalStateException("Shouldn't get here (null token). Last state is " + state() + " currentType:" +
delegate.getCurrentBsonType());
}
return token;
}
示例2: toGsonToken
private static JsonToken toGsonToken(com.fasterxml.jackson.core.JsonToken token) {
switch (token) {
case START_ARRAY:
return JsonToken.BEGIN_ARRAY;
case END_ARRAY:
return JsonToken.END_ARRAY;
case START_OBJECT:
return JsonToken.BEGIN_OBJECT;
case END_OBJECT:
return JsonToken.END_OBJECT;
case FIELD_NAME:
return JsonToken.NAME;
case VALUE_FALSE:
return JsonToken.BOOLEAN;
case VALUE_TRUE:
return JsonToken.BOOLEAN;
case VALUE_NULL:
return JsonToken.NULL;
case VALUE_NUMBER_INT:
return JsonToken.NUMBER;
case VALUE_NUMBER_FLOAT:
return JsonToken.NUMBER;
case VALUE_STRING:
case VALUE_EMBEDDED_OBJECT:
return JsonToken.STRING;
default: // Not semantically equivalent
return JsonToken.NULL;
}
}
示例3: skipValue
public void skipValue() throws IOException {
if (peek() == JsonToken.NAME) {
nextName();
} else {
popStack();
}
}
示例4: skipValue
@Override public void skipValue() throws IOException {
if (peek() == JsonToken.NAME) {
nextName();
} else {
popStack();
}
}
示例5: read
public void read(JsonReader in, Object bean) throws Exception {
while (in.peek() == JsonToken.NAME) {
String fieldName = in.nextName();
PolymorphicField field = polymorphicFields.get(fieldName);
// ignore non-existing fields
if (field!=null) {
field.read(in, bean);
}
}
}
示例6: peek
public JsonToken peek() throws IOException {
if (this.stack.isEmpty()) {
return JsonToken.END_DOCUMENT;
}
Iterator<?> o = peekStack();
if (o instanceof Iterator) {
boolean isObject = this.stack.get(this.stack.size() - 2) instanceof JsonObject;
Iterator<?> iterator = o;
if (!iterator.hasNext()) {
return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
} else {
if (isObject) {
return JsonToken.NAME;
}
this.stack.add(iterator.next());
return peek();
}
} else if (o instanceof JsonObject) {
return JsonToken.BEGIN_OBJECT;
} else {
if (o instanceof JsonArray) {
return JsonToken.BEGIN_ARRAY;
}
if (o instanceof JsonPrimitive) {
JsonPrimitive primitive = (JsonPrimitive) o;
if (primitive.isString()) {
return JsonToken.STRING;
}
if (primitive.isBoolean()) {
return JsonToken.BOOLEAN;
}
if (primitive.isNumber()) {
return JsonToken.NUMBER;
}
throw new AssertionError();
} else if (o instanceof JsonNull) {
return JsonToken.NULL;
} else {
if (o == SENTINEL_CLOSED) {
throw new IllegalStateException("JsonReader is closed");
}
throw new AssertionError();
}
}
}
示例7: peek
@Override public JsonToken peek() throws IOException {
if (stack.isEmpty()) {
return JsonToken.END_DOCUMENT;
}
Object o = peekStack();
if (o instanceof Iterator) {
boolean isObject = stack.get(stack.size() - 2) instanceof JsonObject;
Iterator<?> iterator = (Iterator<?>) o;
if (iterator.hasNext()) {
if (isObject) {
return JsonToken.NAME;
} else {
stack.add(iterator.next());
return peek();
}
} else {
return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
}
} else if (o instanceof JsonObject) {
return JsonToken.BEGIN_OBJECT;
} else if (o instanceof JsonArray) {
return JsonToken.BEGIN_ARRAY;
} else if (o instanceof JsonPrimitive) {
JsonPrimitive primitive = (JsonPrimitive) o;
if (primitive.isString()) {
return JsonToken.STRING;
} else if (primitive.isBoolean()) {
return JsonToken.BOOLEAN;
} else if (primitive.isNumber()) {
return JsonToken.NUMBER;
} else {
throw new AssertionError();
}
} else if (o instanceof JsonNull) {
return JsonToken.NULL;
} else if (o == SENTINEL_CLOSED) {
throw new IllegalStateException("JsonReader is closed");
} else {
throw new AssertionError();
}
}
示例8: readMessage
public static <T> int readMessage(JsonReader reader,String tableName,Class<T> clazz,long last_sync_ts) throws IOException, JSONException,Exception {
String n = null;
int i=0;
while (reader.hasNext()) {
JsonToken peek=reader.peek();
String v = null;
if (peek==JsonToken.BEGIN_OBJECT) {
reader.beginObject();
} else if (peek==JsonToken.NAME) {
n=reader.nextName();
} else if (peek==JsonToken.BEGIN_ARRAY) {
if (n.equals(tableName)) {
i=readJsnArr(reader,tableName,clazz);
} else {
if (n.equals("params")) {
reader.beginArray();
if (reader.hasNext()) {
reader.beginObject();
if (reader.hasNext()) {
n=reader.nextName();
v=reader.nextString();
}
reader.endObject();
}
reader.endArray();
} else {
reader.skipValue();
}
}
} else if (peek==JsonToken.END_OBJECT) {
reader.endObject();
} else if (peek==JsonToken.END_ARRAY) {
reader.endArray();
} else if (peek==JsonToken.STRING) {
reader.skipValue();
} else {
reader.skipValue();
}
}
return i;
}