@Test public void testRetrieveJsonElementFromJsonObject2() { JsonArray arrayElement = new JsonArray().addString("foo"); JsonObject tester = new JsonObject().putElement("elementField", arrayElement); JsonElement testElement = tester.getElement("elementField"); assertEquals(arrayElement.get(0), testElement.asArray().get(0)); }
@Test public void testRetrieveJsonElementFromJsonArray2() { JsonArray arrayElement = new JsonArray().addString("foo"); /* Insert an Object */ JsonArray tester = new JsonArray().addElement(arrayElement); JsonElement testElement = (JsonElement) tester.get(0); assertEquals(arrayElement.get(0), testElement.asArray().get(0)); }
@Test public void testJsonElementConversionWithoutException() { JsonElement objElement = new JsonObject().putString("foo", "bar"); JsonElement arrayElement = new JsonArray().addString("foo"); JsonObject retrievedObject = objElement.asObject(); JsonArray retrievedArray = arrayElement.asArray(); log.debug(retrievedObject.encode()); log.debug(retrievedArray.encode()); }
@Test public void testJsonElementConversionWithException() { JsonElement objElement = new JsonObject().putString("foo", "bar"); try { objElement.asArray(); } catch (ClassCastException e) { return; } fail("Coercing JsonElement(Object) into JsonArray did not throw a ClassCastException"); }