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