當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonToken.STRING屬性代碼示例

本文整理匯總了Java中com.google.gson.stream.JsonToken.STRING屬性的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken.STRING屬性的具體用法?Java JsonToken.STRING怎麽用?Java JsonToken.STRING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.google.gson.stream.JsonToken的用法示例。


在下文中一共展示了JsonToken.STRING屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createJsonReader

/** Forces creation of more strict in string reading if in !lenient mode */
private JsonReader createJsonReader(Reader reader) {
  if (!options.lenient) {
    return new JsonReader(reader) {
      @Override
      public String nextString() throws IOException {
        JsonToken peeked = peek();
        if (peeked == JsonToken.STRING) {
          return super.nextString();
        }
        throw new JsonParseException(
            String.format("In strict mode (!lenient) string read only from string literal, not %s. Path: %s",
                peeked,
                getPath()));
      }
    };
  }
  return new JsonReader(reader);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:GsonMessageBodyProvider.java

示例2: read

@Override
public Date read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }

    if (in.peek() != JsonToken.STRING) {
        throw new JsonParseException("The date should be a string value");
    }

    Date date = deserializeToDate(in.nextString());

    if (dateType == Date.class) {
        return date;
    } else if (dateType == Timestamp.class) {
        return new Timestamp(date.getTime());
    } else if (dateType == java.sql.Date.class) {
        return new java.sql.Date(date.getTime());
    } else {
        // This must never happen: dateType is guarded in the primary constructor
        throw new AssertionError();
    }
}
 
開發者ID:CoryCharlton,項目名稱:BittrexApi,代碼行數:24,代碼來源:DefaultDateTypeAdapter.java

示例3: 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;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:JsonParserReader.java

示例4: 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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:12,代碼來源:JsonTreeReader.java

示例5: 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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:7,代碼來源:JsonTreeReader.java

示例6: read

@Override
public Boolean read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  } else if (in.peek() == JsonToken.STRING) {
    // support strings for compatibility with GSON 1.7
    return Boolean.parseBoolean(in.nextString());
  }
  return in.nextBoolean();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:TypeAdapters.java

示例7: 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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:9,代碼來源:JsonTreeReader.java

示例8: 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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:9,代碼來源:JsonTreeReader.java

示例9: read

public Boolean read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    } else if (in.peek() == JsonToken.STRING) {
        return Boolean.valueOf(Boolean.parseBoolean(in.nextString()));
    } else {
        return Boolean.valueOf(in.nextBoolean());
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:10,代碼來源:TypeAdapters.java

示例10: 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:JsonTreeReader.java

示例11: 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;
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:9,代碼來源:JsonTreeReader.java

示例12: 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:JsonTreeReader.java

示例13: 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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:58,代碼來源:BsonReader.java

示例14: 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();
  }
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:42,代碼來源:JsonTreeReader.java


注:本文中的com.google.gson.stream.JsonToken.STRING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。