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


Java GenericJson類代碼示例

本文整理匯總了Java中com.google.api.client.json.GenericJson的典型用法代碼示例。如果您正苦於以下問題:Java GenericJson類的具體用法?Java GenericJson怎麽用?Java GenericJson使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: signInWithCustomToken

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
private String signInWithCustomToken(String customToken) throws IOException {
  GenericUrl url = new GenericUrl(ID_TOOLKIT_URL + "?key="
      + IntegrationTestUtils.getApiKey());
  Map<String, Object> content = ImmutableMap.<String, Object>of(
      "token", customToken, "returnSecureToken", true);
  HttpRequest request = transport.createRequestFactory().buildPostRequest(url,
      new JsonHttpContent(jsonFactory, content));
  request.setParser(new JsonObjectParser(jsonFactory));
  HttpResponse response = request.execute();
  try {
    GenericJson json = response.parseAs(GenericJson.class);
    return json.get("idToken").toString();
  } finally {
    response.disconnect();
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:17,代碼來源:FirebaseAuthIT.java

示例2: testSetCustomAttributes

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
@Test
public void testSetCustomAttributes() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent(TestUtils.loadResource("createUser.json"));
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  TestResponseInterceptor interceptor = new TestResponseInterceptor();
  userManager.setInterceptor(interceptor);
  // should not throw
  ImmutableMap<String, Object> claims = ImmutableMap.<String, Object>of(
      "admin", true, "package", "gold");
  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  userManager.updateUser(new UpdateRequest("testuser")
      .setCustomClaims(claims), jsonFactory);
  checkRequestHeaders(interceptor);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  interceptor.getResponse().getRequest().getContent().writeTo(out);
  GenericJson parsed = jsonFactory.fromString(new String(out.toByteArray()), GenericJson.class);
  assertEquals("testuser", parsed.get("localId"));
  assertEquals(jsonFactory.toString(claims), parsed.get("customAttributes"));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:25,代碼來源:FirebaseUserManagerTest.java

示例3: getForecastString

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
private List<String> getForecastString(GenericJson content) {
    List<String> response = Lists.newArrayList();
    StringBuilder respLin = new StringBuilder();
    try {
        ArrayMap forecast = (ArrayMap) content.get("forecast");
        ArrayMap simpleforecast = (ArrayMap) forecast.get("simpleforecast");
        ArrayList forecastday = (ArrayList) simpleforecast.get("forecastday");
        Iterator iterator = forecastday.iterator();
        while (iterator.hasNext()) {
            ArrayMap day = (ArrayMap) iterator.next();
            ArrayMap date = (ArrayMap) day.get("date");
            ArrayMap high = (ArrayMap) day.get("high");
            ArrayMap low = (ArrayMap) day.get("low");
            String conditions = (String) day.get("conditions");
            respLin.append(date.get("weekday_short")).append(" ").append((String)high.get("fahrenheit")).append("F/").append((String)low.get("fahrenheit")).append("F ").append("(").append(conditions).append(")").append(" | ");

        }
    } catch (Exception e) {
        log.error("Error obtaining weather!", e);
    }
    String finalstring = respLin.toString().substring(0, respLin.toString().length() - 2);
    response.add(finalstring);
    return response;
}
 
開發者ID:chriskearney,項目名稱:creeper,代碼行數:25,代碼來源:WeatherManager.java

示例4: getCurrentConditionsString

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
private List<String> getCurrentConditionsString(GenericJson content) {
    List<String> response = Lists.newArrayList();
    try {
        ArrayMap current_observation = (ArrayMap) content.get("current_observation");
        Object weather = current_observation.get("weather");
        Object temperature_string = current_observation.get("temperature_string");
        Object wind_string = current_observation.get("wind_string");
        Object relative_humidity = current_observation.get("relative_humidity");
        Object feelslike_string = current_observation.get("feelslike_string");
        ArrayMap display_location = (ArrayMap) current_observation.get("display_location");
        Object full = display_location.get("full");
        response.add(full.toString() + ": " + weather + " | Temperature: " + temperature_string + " | Humidity: " + relative_humidity + " | Feels Like: " + feelslike_string + " | Wind: " + wind_string);
    } catch (Exception e) {
        log.error("Error obtaining weather!", e);
    }
    return response;
}
 
開發者ID:chriskearney,項目名稱:creeper,代碼行數:18,代碼來源:WeatherManager.java

示例5: retryFailures

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
protected <T extends GenericJson> T retryFailures(
    AbstractGoogleClientRequest<T> request, BackOff backOff) throws IOException {
  while (true) {
    try {
      return request.execute();
    } catch (GoogleJsonResponseException e) {
      try {
        long nextPause = backOff.nextBackOffMillis();
        if (nextPause == BackOff.STOP) {
          throw e;
        }
        System.out.printf("Operation failed, retrying in %f seconds.%n", nextPause / 1000.0);
        BackOffUtils.next(Sleeper.DEFAULT, backOff);
      } catch (InterruptedException ie) {
        // Just go straight into retry if interrupted.
      }
    }
  }
}
 
開發者ID:googleads,項目名稱:googleads-shopping-samples,代碼行數:20,代碼來源:BaseWorkflowSample.java

示例6: generateWebserviceResponseJwt

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
/**
 * Generates the linking/signup JWT from a Wallet Object
 *
 * @param object
 * @param resp
 * @return
 * @throws SignatureException
 */
public String generateWebserviceResponseJwt(GenericJson object,
    WebserviceResponse resp) throws SignatureException {

  JsonToken token = new JsonToken(signer);
  token.setAudience(GOOGLE);
  token.setParam("typ", LOYALTY_WEB);
  token.setIssuedAt(new Instant(
      Calendar.getInstance().getTimeInMillis() - 5000L));
  WobPayload payload = new WobPayload();

  if (object != null) {
    object.setFactory(new GsonFactory());
    payload.addObject(object);
  }

  payload.setResponse(resp);
  JsonObject obj = gson.toJsonTree(payload).getAsJsonObject();
  token.getPayloadAsJsonObject().add("payload", obj);
  return token.serializeAndSign();
}
 
開發者ID:android-pay,項目名稱:s2ap-quickstart-java,代碼行數:29,代碼來源:WobUtils.java

示例7: addObject

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
/**
 * Adds the object to the appropriate list
 *
 * @param object
 */
public void addObject(GenericJson object) {
  object.setFactory(jsonFactory);

  if (LoyaltyObject.class.isAssignableFrom(object.getClass())) {
    addLoyaltyObject(gson.fromJson(object.toString(), GenericJson.class));
  } else if (OfferObject.class.isAssignableFrom(object.getClass())) {
    addOfferObject(gson.fromJson(object.toString(), GenericJson.class));
  } else if (GiftCardObject.class.isAssignableFrom(object.getClass())) {
    addGiftCardObject(gson.fromJson(object.toString(), GenericJson.class));
  } else if (LoyaltyClass.class.isAssignableFrom(object.getClass())) {
    addLoyaltyClass(gson.fromJson(object.toString(), GenericJson.class));
  } else if (OfferClass.class.isAssignableFrom(object.getClass())) {
    addOfferClass(gson.fromJson(object.toString(), GenericJson.class));
  } else if (GiftCardClass.class.isAssignableFrom(object.getClass())) {
    addGiftCardClass(gson.fromJson(object.toString(), GenericJson.class));
  } else
    throw new IllegalArgumentException("Invalid Object type: "
        + object.getClass());
}
 
開發者ID:android-pay,項目名稱:s2ap-quickstart-java,代碼行數:25,代碼來源:WobPayload.java

示例8: hitTheEndpoint

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
private void hitTheEndpoint(){

        AsyncCustomEndpoints endpoints = getClient().customEndpoints();
        endpoints.callEndpoint("doit", new GenericJson(), new KinveyListCallback<GenericJson>() {
            @Override
            public void onSuccess(GenericJson[] result) {
                if (result == null){
                    results.setText("nope, got null back!");
                }else{
                    results.setText(result[0].toString()) ;

                }
            }
            @Override
            public void onFailure(Throwable error) {
                results.setText("Uh oh -> " + error);
            }
        });

    }
 
開發者ID:KinveyApps,項目名稱:Kitchensink-Android,代碼行數:21,代碼來源:EndpointFragment.java

示例9: createSignedCustomAuthTokenForUser

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
public String createSignedCustomAuthTokenForUser(
    String uid, Map<String, Object> developerClaims, String issuer, PrivateKey privateKey)
    throws GeneralSecurityException, IOException {
  Preconditions.checkState(uid != null, "Uid must be provided.");
  Preconditions.checkState(issuer != null && !"".equals(issuer), "Must provide an issuer.");
  Preconditions.checkState(uid.length() <= 128, "Uid must be shorter than 128 characters.");

  JsonWebSignature.Header header = new JsonWebSignature.Header().setAlgorithm("RS256");

  long issuedAt = clock.currentTimeMillis() / 1000;
  FirebaseCustomAuthToken.Payload payload =
      new FirebaseCustomAuthToken.Payload()
          .setUid(uid)
          .setIssuer(issuer)
          .setSubject(issuer)
          .setAudience(FirebaseCustomAuthToken.FIREBASE_AUDIENCE)
          .setIssuedAtTimeSeconds(issuedAt)
          .setExpirationTimeSeconds(issuedAt + FirebaseCustomAuthToken.TOKEN_DURATION_SECONDS);

  if (developerClaims != null) {
    Collection<String> reservedNames = payload.getClassInfo().getNames();
    for (String key : developerClaims.keySet()) {
      if (reservedNames.contains(key)) {
        throw new IllegalArgumentException(
            String.format("developer_claims can not contain a reserved key: %s", key));
      }
    }
    GenericJson jsonObject = new GenericJson();
    jsonObject.putAll(developerClaims);
    payload.setDeveloperClaims(jsonObject);
  }

  return JsonWebSignature.signUsingRsaSha256(privateKey, factory, header, payload);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:35,代碼來源:FirebaseTokenFactory.java

示例10: createUser

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
String createUser(CreateRequest request) throws FirebaseAuthException {
  GenericJson response = post(
      "signupNewUser", request.getProperties(), GenericJson.class);
  if (response != null) {
    String uid = (String) response.get("localId");
    if (!Strings.isNullOrEmpty(uid)) {
      return uid;
    }
  }
  throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to create new user");
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:12,代碼來源:FirebaseUserManager.java

示例11: updateUser

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
void updateUser(UpdateRequest request, JsonFactory jsonFactory) throws FirebaseAuthException {
  GenericJson response = post(
      "setAccountInfo", request.getProperties(jsonFactory), GenericJson.class);
  if (response == null || !request.getUid().equals(response.get("localId"))) {
    throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to update user: " + request.getUid());
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:8,代碼來源:FirebaseUserManager.java

示例12: deleteUser

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
void deleteUser(String uid) throws FirebaseAuthException {
  final Map<String, Object> payload = ImmutableMap.<String, Object>of("localId", uid);
  GenericJson response = post(
      "deleteAccount", payload, GenericJson.class);
  if (response == null || !response.containsKey("kind")) {
    throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to delete user: " + uid);
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:9,代碼來源:FirebaseUserManager.java

示例13: testListUsers

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
@Test
public void testListUsers() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent(TestUtils.loadResource("listUsers.json"));
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  TestResponseInterceptor interceptor = new TestResponseInterceptor();
  userManager.setInterceptor(interceptor);

  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  DownloadAccountResponse download = userManager.listUsers(999, null);
  assertEquals(2, download.getUsers().size());
  for (User user : download.getUsers()) {
    ExportedUserRecord userRecord = new ExportedUserRecord(user, jsonFactory);
    checkUserRecord(userRecord);
    assertEquals("passwordHash", userRecord.getPasswordHash());
    assertEquals("passwordSalt", userRecord.getPasswordSalt());
  }
  assertNull(download.getPageToken());
  checkRequestHeaders(interceptor);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  interceptor.getResponse().getRequest().getContent().writeTo(out);
  GenericJson parsed = jsonFactory.fromString(new String(out.toByteArray()), GenericJson.class);
  assertEquals(new BigDecimal(999), parsed.get("maxResults"));
  assertNull(parsed.get("nextPageToken"));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:30,代碼來源:FirebaseUserManagerTest.java

示例14: testListUsersWithPageToken

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
@Test
public void testListUsersWithPageToken() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent(TestUtils.loadResource("listUsers.json"));
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  TestResponseInterceptor interceptor = new TestResponseInterceptor();
  userManager.setInterceptor(interceptor);

  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  DownloadAccountResponse download = userManager.listUsers(999, "token");
  assertEquals(2, download.getUsers().size());
  for (User user : download.getUsers()) {
    ExportedUserRecord userRecord = new ExportedUserRecord(user, jsonFactory);
    checkUserRecord(userRecord);
    assertEquals("passwordHash", userRecord.getPasswordHash());
    assertEquals("passwordSalt", userRecord.getPasswordSalt());
  }
  assertNull(download.getPageToken());
  checkRequestHeaders(interceptor);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  interceptor.getResponse().getRequest().getContent().writeTo(out);
  GenericJson parsed = jsonFactory.fromString(new String(out.toByteArray()), GenericJson.class);
  assertEquals(new BigDecimal(999), parsed.get("maxResults"));
  assertEquals("token", parsed.get("nextPageToken"));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:30,代碼來源:FirebaseUserManagerTest.java

示例15: ensureServiceAccount

import com.google.api.client.json.GenericJson; //導入依賴的package包/類
private static synchronized GenericJson ensureServiceAccount() {
  if (serviceAccount == null) {
    try (InputStream stream = new FileInputStream(IT_SERVICE_ACCOUNT_PATH)) {
      serviceAccount = Utils.getDefaultJsonFactory().fromInputStream(stream, GenericJson.class);
    } catch (IOException e) {
      String msg = String.format("Failed to read service account certificate from %s. "
          + "Integration tests require a service account credential obtained from a Firebase "
          + "project. See CONTRIBUTING.md for more details.", IT_SERVICE_ACCOUNT_PATH);
      throw new RuntimeException(msg, e);
    }
  }
  return serviceAccount;
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:14,代碼來源:IntegrationTestUtils.java


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