本文整理了Java中org.activityinfo.json.Json.parse()
方法的一些代码示例,展示了Json.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.parse()
方法的具体详情如下:
包路径:org.activityinfo.json.Json
类名称:Json
方法名:parse
暂无
代码示例来源:origin: bedatadriven/activityinfo
public JsonValue parse(String json) {
return Json.parse(json);
}
代码示例来源:origin: bedatadriven/activityinfo
@Nullable
@Override
public Optional<JsonValue> getObjectIfPresent(String keyName) {
String jsonString = getItem(keyName);
if(jsonString != null) {
try {
return Optional.of(Json.parse(jsonString));
} catch (Exception e) {
LOGGER.warning("Exception parsing key " + keyName);
}
}
return Optional.absent();
}
代码示例来源:origin: bedatadriven/activityinfo
private static FormClass tryDeserialize(Activity activity, String formClass, byte[] formClassGz) {
try {
JsonValue object;
if (formClassGz != null) {
try(Reader reader = new InputStreamReader(
new GZIPInputStream(new ByteArrayInputStream(formClassGz)), Charsets.UTF_8)) {
object = parse(CharStreams.toString(reader));
}
} else if (!Strings.isNullOrEmpty(formClass)) {
object = parse(formClass);
} else {
return null;
}
return patchDeserializedFormClass(activity, FormClass.fromJson(object));
} catch (IOException e) {
throw new IllegalStateException("Error deserializing form class", e);
}
}
代码示例来源:origin: bedatadriven/activityinfo
public void testIllegalParse() {
try {
Json.parse("{ \"a\": new String() }");
fail("Expected JsonException to be thrown");
} catch (JsonException je) {
// Expected
}
}
代码示例来源:origin: bedatadriven/activityinfo
private FormClass parseResource() throws IOException {
URL resource = Resources.getResource(FormClass.class, "OldFormClass2.json");
String json = Resources.toString(resource, Charsets.UTF_8);
JsonValue element = Json.parse(json);
return FormClass.fromJson(element);
}
代码示例来源:origin: bedatadriven/activityinfo
public void testLegalParse() {
JsonValue obj = Json.parse(
"{ \"a\":1, \"b\":\"hello\", \"c\": true,"
+ "\"d\": null, \"e\": [1,2,3,4], \"f\": {} }");
assertNotNull(obj);
}
代码示例来源:origin: bedatadriven/activityinfo
private UserDatabaseMeta deserialize(String serializedDbMeta) {
return UserDatabaseMeta.fromJson(Json.parse(serializedDbMeta));
}
代码示例来源:origin: bedatadriven/activityinfo
private DatabaseGrant deserialize(String json) {
return DatabaseGrant.fromJson(Json.parse(json));
}
代码示例来源:origin: bedatadriven/activityinfo
private DatabaseMeta deserialze(String json) {
return DatabaseMeta.fromJson(Json.parse(json));
}
代码示例来源:origin: bedatadriven/activityinfo
private FolderFilter(String modelJson) {
UserPermissionModel model = UserPermissionModel.fromJson(Json.parse(modelJson));
for (GrantModel grantModel : model.getGrants()) {
if(grantModel.getResourceId().getDomain() == CuidAdapter.FOLDER_DOMAIN) {
int folderId = CuidAdapter.getLegacyIdFromCuid(grantModel.getResourceId());
folders.add(folderId);
}
}
}
代码示例来源:origin: bedatadriven/activityinfo
public void testStringify() {
String json = "{\"a\":1,\"b\":\"hello\",\"c\":true,"
+ "\"d\":null,\"e\":[1,2,3,4],\"f\":{\"x\":1}}";
assertEquals(json, Json.stringify(Json.parse(json)));
}
代码示例来源:origin: bedatadriven/activityinfo
public void testStringifyNonCycle() {
String json = "{\"a\":1,\"b\":\"hello\",\"c\":true,"
+ "\"d\":null,\"e\":[1,2,3,4],\"f\":{\"x\":1}}";
JsonValue obj = parse(json);
JsonValue obj2 = parse("{\"x\": 1, \"y\":2}");
obj.put("nocycle", obj2);
obj.put("nocycle2", obj2);
try {
Json.stringify(obj);
} catch (JsonException je) {
fail("JsonException for object cycle when none exists: " + je);
}
}
代码示例来源:origin: bedatadriven/activityinfo
public FormClass getFormSchema(ResourceId formId) {
String json = client.resource(root)
.path("resources")
.path("form")
.path(formId.asString())
.path("schema")
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(String.class);
JsonValue jsonObject = parse(json);
FormClass formClass = FormClass.fromJson(jsonObject);
return formClass;
}
代码示例来源:origin: bedatadriven/activityinfo
public void testStringifyCycle() {
String json = "{\"a\":1,\"b\":\"hello\",\"c\":true,"
+ "\"d\":null,\"e\":[1,2,3,4],\"f\":{\"x\":1}}";
JsonValue obj = parse(json);
obj.put("cycle", obj);
try {
Json.stringify(obj);
fail("Expected JsonException for object cycle");
} catch (Exception je) {
}
}
代码示例来源:origin: bedatadriven/activityinfo
public FormTree getFormTree(ResourceId resourceId) {
if(localCatalog.isLocalResource(resourceId)) {
FormTreeBuilder treeBuilder = new FormTreeBuilder(localCatalog);
return treeBuilder.queryTree(resourceId);
} else {
String json = formResource(resourceId).path("tree").get(String.class);
JsonValue object = Json.parse(json);
return JsonFormTreeBuilder.fromJson(object);
}
}
代码示例来源:origin: bedatadriven/activityinfo
public void testStringArrayParse() {
JsonValue jsonValue = Json.parse("[\"a\", \"b\"]");
JsonValue jsonArray = jsonValue;
String concat = "";
for (JsonValue value : jsonArray.values()) {
concat += value.asString();
}
assertEquals("ab", concat);
}
代码示例来源:origin: bedatadriven/activityinfo
private Promise<FormRecordSet> getRecords(final ResourceId formId, final String url) {
return getRaw(url, response -> {
switch (response.getStatusCode()) {
case Response.SC_OK:
return FormRecordSet.fromJson(Json.parse(response.getText()));
case Response.SC_NOT_FOUND:
case Response.SC_FORBIDDEN:
return new FormRecordSet(formId.asString());
default:
throw new ApiException(response.getStatusCode());
}
});
}
代码示例来源:origin: bedatadriven/activityinfo
public void testArrayParse() {
JsonValue jsonValue = Json.parse("[1,2,3,4]");
JsonValue jsonArray = jsonValue;
int count = 0;
double sum = 0;
for (JsonValue value : jsonArray.values()) {
count++;
sum += value.asNumber();
}
assertEquals(4, count);
assertEquals(1d+2d+3d+4d, sum);
}
代码示例来源:origin: bedatadriven/activityinfo
@Override
public Promise<FormMetadata> getFormMetadata(String formId) {
return getRaw(formUrl(formId), response -> {
switch (response.getStatusCode()) {
case 200:
return FormMetadata.fromJson(Json.parse(response.getText()));
case 403:
return FormMetadata.forbidden(ResourceId.valueOf(formId));
case 404:
return FormMetadata.notFound(ResourceId.valueOf(formId));
default:
throw new ApiException(response.getStatusCode());
}
});
}
代码示例来源:origin: bedatadriven/activityinfo
@Test
public void clientSideSerialization() {
QueryModel model = new QueryModel(ResourceId.valueOf("XYZ"));
model.selectRecordId().as("id");
model.selectRecordId();
model.selectExpr("foo").as("foo_column");
String json = model.toJsonString();
System.out.println(json);
QueryModel remodel = QueryModel.fromJson(Json.parse(json));
}
内容来源于网络,如有侵权,请联系作者删除!