@Override public StructuredOutput endObject() { if (nesting.isEmpty()) { throw new IllegalArgumentException("Invalid result structure. No object to close"); } Element e = nesting.get(0); nesting.remove(0); if (e.getType() != ElementType.OBJECT) { throw new IllegalArgumentException("Invalid result structure. No object to close"); } endObject(e.getName()); return this; }
/** * Determines whether the current element is empty * * @return <tt>true</tt> if the current element has no content or children, <tt>false</tt> otherwise */ public boolean isCurrentObjectEmpty() { if (nesting.isEmpty()) { return true; } return nesting.get(0).isEmpty(); }
@Override public StructuredOutput endArray() { if (nesting.isEmpty()) { throw new IllegalArgumentException("Invalid result structure. No array to close"); } Element e = nesting.get(0); nesting.remove(0); if (e.getType() != ElementType.ARRAY) { throw new IllegalArgumentException("Invalid result structure. No array to close"); } endArray(e.getName()); return this; }
/** * Returns the type of the current element. * * @return the type of the current element */ protected ElementType getCurrentType() { if (nesting.isEmpty()) { return ElementType.UNKNOWN; } return nesting.get(0).getType(); }
@Override public StructuredOutput property(String name, Object data) { if (getCurrentType() != ElementType.OBJECT && getCurrentType() != ElementType.ARRAY) { throw new IllegalArgumentException("Invalid result structure. Cannot place a property here."); } writeProperty(name, data); nesting.get(0).setEmpty(false); return this; }