public JsonRepresentation arrayAdd(final int value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final double value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final float value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final boolean value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final String value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final long value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(value); return this; }
public JsonRepresentation arrayAdd(final Object value) { if (!isArray()) { throw new IllegalStateException("does not represent array"); } asArrayNode().add(new POJONode(value)); return this; }
public JsonRepresentation arraySetElementAt(final int i, final JsonRepresentation objectRepr) { ensureIsAnArrayAtLeastAsLargeAs(i+1); if (objectRepr.isArray()) { throw new IllegalArgumentException("Representation being set cannot be an array"); } // can safely downcast because *this* representation is an array final ArrayNode arrayNode = (ArrayNode) jsonNode; arrayNode.set(i, objectRepr.asJsonNode()); return this; }
private JsonRepresentation getMap(final String path, final JsonNode node) { if (representsNull(node)) { return null; } if (isArray(node) || node.isValueNode()) { throw new IllegalArgumentException(formatExMsg(path, "is not a map")); } return new JsonRepresentation(node); }
public boolean isLink(final JsonNode node) { if (representsNull(node) || isArray(node) || node.isValueNode()) { return false; } final LinkRepresentation link = new LinkRepresentation(node); if (link.getHref() == null) { return false; } return true; }
@Test public void forList() throws IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("aSubList"); assertThat(listRepresentation.isArray(), is(true)); }
@Test public void forMap() throws IOException { assertThat(jsonRepresentation.isArray(), is(false)); assertThat(jsonRepresentation.isMap(), is(true)); assertThat(jsonRepresentation.isValue(), is(false)); }
@Test public void newArray() throws Exception { final JsonRepresentation jsonRepresentation = JsonRepresentation.newArray(); assertThat(jsonRepresentation.isArray(), is(true)); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void newArray() throws Exception { final JsonRepresentation jsonRepresentation = JsonRepresentation.newArray(); assertThat(jsonRepresentation.isArray(), is(true)); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void forListWithMultipleCriteriaMatchingMultiple() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void forListWithMultipleCriteriaMatchingMultiple() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void whenStartingWithList() throws IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks"); final JsonRepresentation representation = listRepresentation.getRepresentation("[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void forValue() throws IOException { final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("aString"); assertThat(valueRepresentation.isArray(), is(false)); assertThat(valueRepresentation.isMap(), is(false)); assertThat(valueRepresentation.isValue(), is(true)); }
@Test public void whenStartingWithList() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks"); final JsonRepresentation representation = listRepresentation.getRepresentation("[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@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)); }