use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.
the class RelationshipsIT method testGetParent.
/**
* @throws Exception
*/
@Test
public void testGetParent() throws Exception {
resp = Unirest.get(url(DB, COLL_PARENT, "parent")).basicAuth(ADMIN_ID, ADMIN_PWD).asString();
JsonValue rbody = Json.parse(resp.getBody());
Assert.assertTrue("check _links", rbody != null && rbody.isObject() && rbody.asObject().get("_links") != null && rbody.asObject().get("_links").isObject() && rbody.asObject().get("_links").asObject().get("children") != null && rbody.asObject().get("_links").asObject().get("children").isObject() && rbody.asObject().get("_links").asObject().get("children").asObject().get("href") != null && rbody.asObject().get("_links").asObject().get("children").asObject().get("href").isString());
String childrenUrl = rbody.asObject().get("_links").asObject().get("children").asObject().get("href").asString();
Assert.assertTrue("check href", childrenUrl.endsWith("filter={'_id':{'$in':[0,1,2,3,4,5,6,7,8,9]}}"));
}
use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.
the class BulkRequestsIT method testBulkPostCreate.
/**
* @throws Exception
*/
@Test
public void testBulkPostCreate() throws Exception {
resp = Unirest.post(url(DB, COLL)).basicAuth(ADMIN_ID, ADMIN_PWD).header("content-type", "application/json").body("[{'seq': 1 },{'seq': 2 },{'seq': 3 },{'seq': 4 }]").asString();
Assert.assertEquals("check response status of create test data", HttpStatus.SC_OK, resp.getStatus());
JsonValue rbody = Json.parse(resp.getBody().toString());
Assert.assertTrue("check response body to be a json object", rbody != null && rbody.isObject());
JsonValue embedded = rbody.asObject().get("_embedded");
Assert.assertTrue("check response body to have _embedded json object", embedded != null && embedded.isObject());
JsonValue rhresult = embedded.asObject().get("rh:result");
Assert.assertTrue("check response body to have rh:result json array", rhresult != null && rhresult.isArray());
Assert.assertTrue("check rh:result json array to have 1 element", rhresult.asArray().size() == 1);
JsonValue result = rhresult.asArray().get(0);
Assert.assertTrue("check rh:result element to be a json object", result.isObject());
JsonValue links = result.asObject().get("_links");
Assert.assertTrue("check rh:result element to have links json object", links != null && links.isObject());
JsonValue newdoc = links.asObject().get("rh:newdoc");
Assert.assertTrue("check rh:result element links json object to have rh:newdoc array with 4 elements", newdoc != null && newdoc.isArray() && newdoc.asArray().size() == 4);
JsonValue inserted = result.asObject().get("inserted");
Assert.assertTrue("check rhresult element to have the 'inserted' numeric property equal to 4", inserted != null && inserted.isNumber() && inserted.asInt() == 4);
}
use of com.eclipsesource.json.JsonValue in project java-koofr by koofr.
the class Transmogrifier method genericJsonResponse.
public static Object genericJsonResponse(JsonValue v) throws JsonException {
if (v.isNumber()) {
return v.asDouble();
} else if (v.isString()) {
return v.asString();
} else if (v.isArray()) {
List<Object> rv = new ArrayList<Object>();
JsonArray a = v.asArray();
int len = a.size();
for (int i = 0; i < len; i++) {
rv.add(genericJsonResponse(a.get(i)));
}
return rv;
} else if (v.isBoolean()) {
return v.asBoolean();
} else if (v.isObject()) {
Iterator<Member> i = v.asObject().iterator();
HashMap<String, Object> rv = new HashMap<String, Object>();
while (i.hasNext()) {
Member m = i.next();
JsonValue sv = m.getValue();
rv.put(m.getName(), genericJsonResponse(sv));
}
return rv;
} else {
throw new JsonException("Unsupported type: " + v + " (" + v.getClass().getName() + ")");
}
}
use of com.eclipsesource.json.JsonValue in project java-koofr by koofr.
the class Transmogrifier method mapObjectUnsafe.
@SuppressWarnings("rawtypes")
protected static JsonValue mapObjectUnsafe(Object o) throws JsonException, IllegalAccessException {
if (o == null) {
return null;
} else if (o instanceof Integer) {
return Json.value((Integer) o);
} else if (o instanceof Long) {
return Json.value((Long) o);
} else if (o instanceof Double) {
return Json.value((Double) o);
} else if (o instanceof Boolean) {
return Json.value((Boolean) o);
} else if (o instanceof String) {
return Json.value((String) o);
} else if (o.getClass().isArray()) {
JsonArray rv = new JsonArray();
int len = Array.getLength(o);
for (int i = 0; i < len; i++) {
JsonValue v = mapObjectUnsafe(Array.get(o, i));
if (v != null) {
rv.add(v);
}
}
return rv;
} else if (o instanceof JsonBase) {
JsonObject rv = new JsonObject();
Field[] fields = o.getClass().getFields();
for (Field f : fields) {
if ((f.getModifiers() & Modifier.PUBLIC) == 0 || (f.getModifiers() & Modifier.STATIC) != 0 || (f.getModifiers() & Modifier.TRANSIENT) != 0 || (f.getModifiers() & Modifier.VOLATILE) != 0 || (f.getModifiers() & Modifier.NATIVE) != 0) {
continue;
}
JsonValue v = mapObjectUnsafe(f.get(o));
if (v != null) {
rv.add(f.getName(), v);
}
}
return rv;
} else if (List.class.isAssignableFrom(o.getClass())) {
JsonArray rv = new JsonArray();
for (Object e : List.class.cast(o)) {
JsonValue v = mapObjectUnsafe(e);
if (v != null) {
rv.add(v);
}
}
return rv;
} else if (Map.class.isAssignableFrom(o.getClass())) {
JsonObject rv = new JsonObject();
Map m = Map.class.cast(o);
for (Object k : m.keySet()) {
JsonValue v = mapObjectUnsafe(m.get(k));
if (v != null) {
rv.add((String) k, v);
}
}
return rv;
} else {
throw new JsonException("Unsupported source type: " + o.getClass().getName());
}
}
use of com.eclipsesource.json.JsonValue in project packr by libgdx.
the class PackrReduce method minimizeJre.
/**
* Tries to shrink the size of the JRE by deleting unused files and possibly removing items from the included jars of the JRE.
*
* @param output the directory to save the minimized JRE into
* @param config the options for minimizing the JRE
*
* @throws IOException if an IO error occurs
* @throws ArchiveException if an archive error occurs
* @throws CompressorException if a compression error occurs
*/
static void minimizeJre(File output, PackrConfig config) throws IOException, CompressorException, ArchiveException {
if (config.minimizeJre == null) {
return;
}
System.out.println("Minimizing JRE ...");
JsonObject minimizeJson = readMinimizeProfile(config);
if (minimizeJson != null) {
if (config.verbose) {
System.out.println(" # Removing files and directories in profile '" + config.minimizeJre + "' ...");
}
JsonArray reduceArray = minimizeJson.get("reduce").asArray();
for (JsonValue reduce : reduceArray) {
String path = reduce.asObject().get("archive").asString();
File file = new File(output, path);
if (!file.exists()) {
if (config.verbose) {
System.out.println(" # No file or directory '" + file.getPath() + "' found, skipping");
}
continue;
}
boolean needsUnpack = !file.isDirectory();
File fileNoExt = needsUnpack ? new File(output, path.contains(".") ? path.substring(0, path.lastIndexOf('.')) : path) : file;
if (needsUnpack) {
if (config.verbose) {
System.out.println(" # Unpacking '" + file.getPath() + "' ...");
}
ArchiveUtils.extractArchive(file.toPath(), fileNoExt.toPath());
}
JsonArray removeArray = reduce.asObject().get("paths").asArray();
for (JsonValue remove : removeArray) {
File removeFile = new File(fileNoExt, remove.asString());
if (removeFile.exists()) {
if (removeFile.isDirectory()) {
PackrFileUtils.deleteDirectory(removeFile);
} else {
Files.deleteIfExists(removeFile.toPath());
}
} else {
if (config.verbose) {
System.out.println(" # No file or directory '" + removeFile.getPath() + "' found");
}
}
}
if (needsUnpack) {
if (config.verbose) {
System.out.println(" # Repacking '" + file.getPath() + "' ...");
}
createZipFileFromDirectory(config, file, fileNoExt);
}
}
JsonArray removeArray = minimizeJson.get("remove").asArray();
for (JsonValue remove : removeArray) {
String platform = remove.asObject().get("platform").asString();
if (!matchPlatformString(platform, config)) {
continue;
}
JsonArray removeFilesArray = remove.asObject().get("paths").asArray();
for (JsonValue removeFile : removeFilesArray) {
removeFileWildcard(output, removeFile.asString(), config);
}
}
}
}
Aggregations