Java Code Examples for com.google.api.client.json.JsonToken#VALUE_NUMBER_INT

The following examples show how to use com.google.api.client.json.JsonToken#VALUE_NUMBER_INT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JacksonFactory.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
static JsonToken convert(com.fasterxml.jackson.core.JsonToken token) {
  if (token == null) {
    return null;
  }
  switch (token) {
    case END_ARRAY:
      return JsonToken.END_ARRAY;
    case START_ARRAY:
      return JsonToken.START_ARRAY;
    case END_OBJECT:
      return JsonToken.END_OBJECT;
    case START_OBJECT:
      return JsonToken.START_OBJECT;
    case VALUE_FALSE:
      return JsonToken.VALUE_FALSE;
    case VALUE_TRUE:
      return JsonToken.VALUE_TRUE;
    case VALUE_NULL:
      return JsonToken.VALUE_NULL;
    case VALUE_STRING:
      return JsonToken.VALUE_STRING;
    case VALUE_NUMBER_FLOAT:
      return JsonToken.VALUE_NUMBER_FLOAT;
    case VALUE_NUMBER_INT:
      return JsonToken.VALUE_NUMBER_INT;
    case FIELD_NAME:
      return JsonToken.FIELD_NAME;
    default:
      return JsonToken.NOT_AVAILABLE;
  }
}
 
Example 2
Source File: AndroidJsonParser.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public JsonToken nextToken() throws IOException {
  if (currentToken != null) {
    switch (currentToken) {
      case START_ARRAY:
        reader.beginArray();
        currentNameStack.add(null);
        break;
      case START_OBJECT:
        reader.beginObject();
        currentNameStack.add(null);
        break;
      default:
        break;
    }
  }
  // work around bug in GSON parser that it throws an EOFException for an empty document
  // see http://github.com/google/gson/issues/330
  android.util.JsonToken peek;
  try {
    peek = reader.peek();
  } catch (EOFException e) {
    peek = android.util.JsonToken.END_DOCUMENT;
  }
  switch (peek) {
    case BEGIN_ARRAY:
      currentText = "[";
      currentToken = JsonToken.START_ARRAY;
      break;
    case END_ARRAY:
      currentText = "]";
      currentToken = JsonToken.END_ARRAY;
      currentNameStack.remove(currentNameStack.size() - 1);
      reader.endArray();
      break;
    case BEGIN_OBJECT:
      currentText = "{";
      currentToken = JsonToken.START_OBJECT;
      break;
    case END_OBJECT:
      currentText = "}";
      currentToken = JsonToken.END_OBJECT;
      currentNameStack.remove(currentNameStack.size() - 1);
      reader.endObject();
      break;
    case BOOLEAN:
      if (reader.nextBoolean()) {
        currentText = "true";
        currentToken = JsonToken.VALUE_TRUE;
      } else {
        currentText = "false";
        currentToken = JsonToken.VALUE_FALSE;
      }
      break;
    case NULL:
      currentText = "null";
      currentToken = JsonToken.VALUE_NULL;
      reader.nextNull();
      break;
    case STRING:
      currentText = reader.nextString();
      currentToken = JsonToken.VALUE_STRING;
      break;
    case NUMBER:
      currentText = reader.nextString();
      currentToken =
          currentText.indexOf('.') == -1
              ? JsonToken.VALUE_NUMBER_INT
              : JsonToken.VALUE_NUMBER_FLOAT;
      break;
    case NAME:
      currentText = reader.nextName();
      currentToken = JsonToken.FIELD_NAME;
      currentNameStack.set(currentNameStack.size() - 1, currentText);
      break;
    default:
      currentText = null;
      currentToken = null;
  }
  return currentToken;
}
 
Example 3
Source File: GsonParser.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public JsonToken nextToken() throws IOException {
  if (currentToken != null) {
    switch (currentToken) {
      case START_ARRAY:
        reader.beginArray();
        currentNameStack.add(null);
        break;
      case START_OBJECT:
        reader.beginObject();
        currentNameStack.add(null);
        break;
      default:
        break;
    }
  }
  // work around bug in GSON parser that it throws an EOFException for an empty document
  // see https://github.com/google/gson/issues/330
  com.google.gson.stream.JsonToken peek;
  try {
    peek = reader.peek();
  } catch (EOFException e) {
    peek = com.google.gson.stream.JsonToken.END_DOCUMENT;
  }
  switch (peek) {
    case BEGIN_ARRAY:
      currentText = "[";
      currentToken = JsonToken.START_ARRAY;
      break;
    case END_ARRAY:
      currentText = "]";
      currentToken = JsonToken.END_ARRAY;
      currentNameStack.remove(currentNameStack.size() - 1);
      reader.endArray();
      break;
    case BEGIN_OBJECT:
      currentText = "{";
      currentToken = JsonToken.START_OBJECT;
      break;
    case END_OBJECT:
      currentText = "}";
      currentToken = JsonToken.END_OBJECT;
      currentNameStack.remove(currentNameStack.size() - 1);
      reader.endObject();
      break;
    case BOOLEAN:
      if (reader.nextBoolean()) {
        currentText = "true";
        currentToken = JsonToken.VALUE_TRUE;
      } else {
        currentText = "false";
        currentToken = JsonToken.VALUE_FALSE;
      }
      break;
    case NULL:
      currentText = "null";
      currentToken = JsonToken.VALUE_NULL;
      reader.nextNull();
      break;
    case STRING:
      currentText = reader.nextString();
      currentToken = JsonToken.VALUE_STRING;
      break;
    case NUMBER:
      currentText = reader.nextString();
      currentToken =
          currentText.indexOf('.') == -1
              ? JsonToken.VALUE_NUMBER_INT
              : JsonToken.VALUE_NUMBER_FLOAT;
      break;
    case NAME:
      currentText = reader.nextName();
      currentToken = JsonToken.FIELD_NAME;
      currentNameStack.set(currentNameStack.size() - 1, currentText);
      break;
    default:
      currentText = null;
      currentToken = null;
  }
  return currentToken;
}