本文整理汇总了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"));
}
示例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"));
}
示例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"));
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}