当前位置: 首页>>代码示例>>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;未经允许,请勿转载。