本文整理匯總了Java中com.google.gson.stream.JsonToken.NUMBER屬性的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken.NUMBER屬性的具體用法?Java JsonToken.NUMBER怎麽用?Java JsonToken.NUMBER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.google.gson.stream.JsonToken
的用法示例。
在下文中一共展示了JsonToken.NUMBER屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: nextString
public String nextString() throws IOException {
JsonToken token = peek();
if (token == JsonToken.STRING || token == JsonToken.NUMBER) {
return ((JsonPrimitive) popStack()).getAsString();
}
throw new IllegalStateException("Expected " + JsonToken.STRING + " but was " + token);
}
示例3: nextDouble
public double nextDouble() throws IOException {
JsonToken token = peek();
if (token == JsonToken.NUMBER || token == JsonToken.STRING) {
double result = ((JsonPrimitive) peekStack()).getAsDouble();
if (isLenient() || !(Double.isNaN(result) || Double.isInfinite(result))) {
popStack();
return result;
}
throw new NumberFormatException("JSON forbids NaN and infinities: " + result);
}
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
示例4: nextLong
public long nextLong() throws IOException {
JsonToken token = peek();
if (token == JsonToken.NUMBER || token == JsonToken.STRING) {
long result = ((JsonPrimitive) peekStack()).getAsLong();
popStack();
return result;
}
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
示例5: nextInt
public int nextInt() throws IOException {
JsonToken token = peek();
if (token == JsonToken.NUMBER || token == JsonToken.STRING) {
int result = ((JsonPrimitive) peekStack()).getAsInt();
popStack();
return result;
}
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
示例6: nextString
@Override public String nextString() throws IOException {
JsonToken token = peek();
if (token != JsonToken.STRING && token != JsonToken.NUMBER) {
throw new IllegalStateException("Expected " + JsonToken.STRING + " but was " + token);
}
return ((JsonPrimitive) popStack()).getAsString();
}
示例7: nextDouble
@Override public double nextDouble() throws IOException {
JsonToken token = peek();
if (token != JsonToken.NUMBER && token != JsonToken.STRING) {
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
double result = ((JsonPrimitive) peekStack()).getAsDouble();
if (!isLenient() && (Double.isNaN(result) || Double.isInfinite(result))) {
throw new NumberFormatException("JSON forbids NaN and infinities: " + result);
}
popStack();
return result;
}
示例8: nextLong
@Override public long nextLong() throws IOException {
JsonToken token = peek();
if (token != JsonToken.NUMBER && token != JsonToken.STRING) {
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
long result = ((JsonPrimitive) peekStack()).getAsLong();
popStack();
return result;
}
示例9: nextInt
@Override public int nextInt() throws IOException {
JsonToken token = peek();
if (token != JsonToken.NUMBER && token != JsonToken.STRING) {
throw new IllegalStateException("Expected " + JsonToken.NUMBER + " but was " + token);
}
int result = ((JsonPrimitive) peekStack()).getAsInt();
popStack();
return result;
}
示例10: 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;
}
示例11: 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();
}
}
}
示例12: 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();
}
}