Esempio n. 1
0
  @Test
  public void testRetrieveJsonElementFromJsonObject() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    JsonObject tester = new JsonObject().putElement("elementField", objElement);

    JsonElement testElement = tester.getElement("elementField");

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
Esempio n. 2
0
  @Test
  public void testRetrieveJsonElementFromJsonArray() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    /* Insert an Object */
    JsonArray tester = new JsonArray().addElement(objElement);

    JsonElement testElement = (JsonElement) tester.get(0);

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
Esempio n. 3
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());
  }
Esempio n. 4
0
  @Test
  public void testJsonElementConversionWithException2() {
    JsonElement arrayElement = new JsonArray().addString("foo");

    try {
      arrayElement.asObject();
    } catch (ClassCastException e) {
      return;
    }

    fail("Coercing JsonElement(Array) into JsonObject did not throw a ClassCastException");
  }