/** * Convert underlying representation into an object (map). */ protected ObjectNode asObjectNode() { if (!isMap()) { throw new IllegalStateException("does not represent map"); } return (ObjectNode) asJsonNode(); }
public R withExtensions(final JsonRepresentation extensions) { if (!extensions.isMap()) { throw new IllegalArgumentException("extensions must be a map"); } representation.mapPut("extensions", extensions); return cast(this); }
public JsonRepresentation mapPut(final String key, final double value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value); return this; }
public JsonRepresentation mapPut(final String key, final int value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value); return this; }
public JsonRepresentation mapPut(final String key, final JsonNode value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } if (value == null) { return this; } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value); return this; }
public JsonRepresentation mapPut(final String key, final float value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value); return this; }
public JsonRepresentation mapPut(final String key, final JsonRepresentation value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } if (value == null) { return this; } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value.asJsonNode()); return this; }
@Test public void happyCase() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation jsonRepresentation = JsonRepresentation.newMap(); assertThat(jsonRepresentation.isMap(), is(true)); }
public JsonRepresentation mapPut(final String key, final Object value) { if (!isMap()) { throw new IllegalStateException("does not represent map"); } final Path path = Path.parse(key); final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead()); node.put(path.getTail(), value != null ? new POJONode(value) : NullNode.getInstance()); return this; }
@Test public void whenWhitespaceOnlyString() throws Exception { representation = DomainResourceHelper.readAsMap(" \t "); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void whenEmptyString() throws Exception { representation = DomainResourceHelper.readAsMap(""); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void forMap() throws IOException { assertThat(jsonRepresentation.isArray(), is(false)); assertThat(jsonRepresentation.isMap(), is(true)); assertThat(jsonRepresentation.isValue(), is(false)); }
@Test public void forMap() throws IOException { final JsonRepresentation mapRepresentation = jsonRepresentation.getRepresentation("aLink"); assertThat(mapRepresentation.getString("rel"), is("someRel")); assertThat(mapRepresentation.isMap(), is(true)); }
@Test public void emptyMap() throws Exception { representation = DomainResourceHelper.readAsMap("{}"); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void forPath() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("aSubMap.aLink"); assertThat(representation.isMap(), is(true)); assertThat(representation.getString("href"), is("http://foo/bar")); }
@Test public void forPath() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("aSubMap.aLink"); assertThat(representation.isMap(), is(true)); assertThat(representation.getString("href"), is("http://foo/bar")); }
@Test public void getProperties() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation properties = representation.getProperties(); final JsonRepresentation members = representation.getMembers(); assertThat(members.size(), is(12)); assertThat(properties.isMap(), is(true)); assertThat(properties.size(), is(10)); }
@Test public void getProperties() throws IOException { final JsonRepresentation properties = representation.getProperties(); final JsonRepresentation members = representation.getMembers(); assertThat(members.size(), is(12)); assertThat(properties.isMap(), is(true)); assertThat(properties.size(), is(10)); }
@Test public void forList() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("list.json")); assertThat(jsonRepresentation.isArray(), is(true)); assertThat(jsonRepresentation.isMap(), is(false)); assertThat(jsonRepresentation.isValue(), is(false)); }
@Test public void getProperties() throws IOException { final JsonRepresentation collections = representation.getCollections(); final JsonRepresentation members = representation.getMembers(); assertThat(members.size(), is(12)); assertThat(collections.isMap(), is(true)); assertThat(collections.size(), is(1)); }