default Integer getInt(final String... labels) { return getJsonObject().getInt(labels); }
public void shouldAllowPutOfNullValue() { JsonElement x=null; JsonObject o = object().put("x", x).get(); assertThat(o.getInt("x"), CoreMatchers.nullValue()); }
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()); }
public void shouldFlatten() { JsonObject obj = object(field("x", object(field("y", array(primitive(1),primitive(2),object(field("foo","bar"))))))); JsonObject flattened = obj.flatten(":"); assertThat(flattened.getInt("x:y:0")).isEqualTo(1); assertThat(flattened.getInt("x:y:1")).isEqualTo(2); assertThat(flattened.getString("x:y:2:foo")).isEqualTo("bar"); }
public void shouldAddFields() { JsonObject object = object(field("meaningoflife", 42), field("foo", primitive("bar")), field("list",array("stuff"))); assertThat(object.getInt("meaningoflife"), is(42)); assertThat(object.getString("foo"), is("bar")); assertThat(object.getArray("list").get(0).asString(), is("stuff")); }
assertTrue(object.getBoolean("a","b","c"), "or like this"); assertTrue(object.getInt("a","b","d") == 42, "or an integer"); assertTrue(object.getString("a","b","e").equals("hi!"),