default JsonObject getObject(@Nonnull String... labels) { return getJsonObject().getObject(labels); }
public void shouldHandleJsonNullsOnGet() { JsonObject o = object().put("x", JsonPrimitive.JSON_NULL).get(); // should return the json null assertThat((JsonPrimitive)o.get("x"), CoreMatchers.notNullValue()); // these should all return a java null assertThat(o.getInt("x"), CoreMatchers.nullValue()); assertThat(o.getLong("x"), CoreMatchers.nullValue()); assertThat(o.getFloat("x"), CoreMatchers.nullValue()); assertThat(o.getDouble("x"), CoreMatchers.nullValue()); assertThat(o.getBoolean("x"), CoreMatchers.nullValue()); assertThat(o.getString("x"), CoreMatchers.nullValue()); assertThat(o.getArray("x"), CoreMatchers.nullValue()); assertThat(o.getObject("x"), CoreMatchers.nullValue()); }
@Test(expectedExceptions=IllegalStateException.class) public void shouldNotAllowMutationsOnObjectInObject() { JsonObject object = object(field("f", object(field("1",1)))); JsonObject clone = object.immutableClone(); assertThat(clone).isEqualTo(object); clone.getObject("f").put("2",2); }
public void shouldRemoveEmptyElements() { JsonObject jsonObject = object().put("empty", object().get()).put("empty2", nullValue()).put("empty3", new JsonArray()).get(); jsonObject.removeEmpty(); assertThat("should leave empty objects",jsonObject.getObject("empty"), is(object().get())); Assert.assertEquals(jsonObject.get("empty2"), null); Assert.assertEquals(jsonObject.get("empty3"), null); }
assertTrue(object.getObject("a","b").isObject(), "and objects");