本文整理汇总了Java中com.google.gson.stream.JsonToken.BEGIN_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.BEGIN_ARRAY属性的具体用法?Java JsonToken.BEGIN_ARRAY怎么用?Java JsonToken.BEGIN_ARRAY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.gson.stream.JsonToken
的用法示例。
在下文中一共展示了JsonToken.BEGIN_ARRAY属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: read
public Map<K, V> read(JsonReader in) throws IOException {
JsonToken peek = in.peek();
if (peek == JsonToken.NULL) {
in.nextNull();
return null;
}
Map<K, V> map = (Map) this.constructor.construct();
K key;
if (peek == JsonToken.BEGIN_ARRAY) {
in.beginArray();
while (in.hasNext()) {
in.beginArray();
key = this.keyTypeAdapter.read(in);
if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
throw new JsonSyntaxException("duplicate key: " + key);
}
in.endArray();
}
in.endArray();
return map;
}
in.beginObject();
while (in.hasNext()) {
JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in);
key = this.keyTypeAdapter.read(in);
if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
throw new JsonSyntaxException("duplicate key: " + key);
}
}
in.endObject();
return map;
}
示例3: parseParams
protected Object parseParams(JsonReader in, String method) throws IOException {
JsonToken next = in.peek();
if (next == JsonToken.NULL) {
in.nextNull();
return null;
}
Type[] parameterTypes = getParameterTypes(method);
if (parameterTypes.length == 1) {
return fromJson(in, parameterTypes[0]);
}
if (parameterTypes.length > 1 && next == JsonToken.BEGIN_ARRAY) {
List<Object> parameters = new ArrayList<Object>(parameterTypes.length);
int index = 0;
in.beginArray();
while (in.hasNext()) {
Type parameterType = index < parameterTypes.length ? parameterTypes[index] : null;
Object parameter = fromJson(in, parameterType);
parameters.add(parameter);
index++;
}
in.endArray();
while (index < parameterTypes.length) {
parameters.add(null);
index++;
}
return parameters;
}
return new JsonParser().parse(in);
}
示例4: toGsonToken
private static JsonToken toGsonToken(BsonType type) {
final JsonToken token;
switch (type) {
case END_OF_DOCUMENT:
token = JsonToken.END_DOCUMENT;
break;
case DOUBLE:
token = JsonToken.NUMBER;
break;
case STRING:
token = JsonToken.STRING;
break;
case DOCUMENT:
token = JsonToken.BEGIN_OBJECT;
break;
case ARRAY:
token = JsonToken.BEGIN_ARRAY;
break;
case OBJECT_ID:
token = JsonToken.STRING;
break;
case BOOLEAN:
token = JsonToken.BOOLEAN;
break;
case DATE_TIME:
token = JsonToken.NUMBER;
break;
case NULL:
token = JsonToken.NULL;
break;
case REGULAR_EXPRESSION:
token = JsonToken.STRING;
break;
case SYMBOL:
token = JsonToken.STRING;
break;
case INT32:
token = JsonToken.NUMBER;
break;
case INT64:
token = JsonToken.NUMBER;
break;
case TIMESTAMP:
token = JsonToken.NUMBER;
break;
case DECIMAL128:
token = JsonToken.NUMBER;
break;
case BINARY:
token = JsonToken.STRING;
break;
default:
// not really sure what to do with this type
token = JsonToken.NULL;
}
return token;
}
示例5: 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();
}
}
}
示例6: 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();
}
}
示例7: 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;
}