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


Java JsonFactory.fromString方法代碼示例

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


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

示例1: testSetCustomAttributes

import com.google.api.client.json.JsonFactory; //導入方法依賴的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

示例2: testListUsers

import com.google.api.client.json.JsonFactory; //導入方法依賴的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

示例3: testListUsersWithPageToken

import com.google.api.client.json.JsonFactory; //導入方法依賴的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

示例4: load

import com.google.api.client.json.JsonFactory; //導入方法依賴的package包/類
public static JsonKey load(JsonFactory jsonFactory, InputStream inputStream)
    throws IOException {
  InputStreamReader reader = new InputStreamReader(inputStream,
      Charsets.UTF_8);
  try {
    Secret decoded = Secret.fromString(CharStreams.toString(reader));
    return jsonFactory.fromString(decoded.getPlainText(), JsonKey.class);
  } finally {
    inputStream.close();
  }
}
 
開發者ID:jenkinsci,項目名稱:google-oauth-plugin,代碼行數:12,代碼來源:JsonKey.java

示例5: parseString

import com.google.api.client.json.JsonFactory; //導入方法依賴的package包/類
public ArrayList<ContentProviderOperation> parseString(String sessionsJson, String tracksJson) {
    JsonFactory jsonFactory = new AndroidJsonFactory();
    try {
        SessionsResponse sessions = jsonFactory.fromString(sessionsJson, SessionsResponse.class);
        TracksResponse tracks =
                jsonFactory.fromString(tracksJson, TracksResponse.class);
        return buildContentProviderOperations(sessions, null, tracks);
    } catch (IOException e) {
        LOGE(TAG, "Error reading speakers from packaged data", e);
        return Lists.newArrayList();
    }
}
 
開發者ID:TheDeltaProgram,項目名稱:iosched2013,代碼行數:13,代碼來源:SessionsHandler.java

示例6: parseString

import com.google.api.client.json.JsonFactory; //導入方法依賴的package包/類
public ArrayList<ContentProviderOperation> parseString(String json) {
    JsonFactory jsonFactory = new AndroidJsonFactory();
    try {
        PresentersResponse presenters = jsonFactory.fromString(json, PresentersResponse.class);
        return buildContentProviderOperations(presenters);
    } catch (IOException e) {
        LOGE(TAG, "Error reading speakers from packaged data", e);
        return Lists.newArrayList();
    }
}
 
開發者ID:TheDeltaProgram,項目名稱:iosched2013,代碼行數:11,代碼來源:SpeakersHandler.java

示例7: newUser

import com.google.api.client.json.JsonFactory; //導入方法依賴的package包/類
private static ExportedUserRecord newUser(String uid) throws IOException {
  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  DownloadAccountResponse.User parsed = jsonFactory.fromString(
      String.format("{\"localId\":\"%s\"}", uid), DownloadAccountResponse.User.class);
  return new ExportedUserRecord(parsed, jsonFactory);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:7,代碼來源:ListUsersPageTest.java


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