本文整理匯總了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);
}