public JsonObject getAsObject() { throw new JsonException("Not a JSON object") ; }
public JsonBoolean getAsBoolean() { throw new JsonException("Not a JSON boolean") ; }
public JsonArray getAsArray() { throw new JsonException("Not a JSON array") ; }
public JsonNumber getAsNumber() { throw new JsonException("Not a JSON number") ; }
public JsonString getAsString() { throw new JsonException("Not a JSON string") ; }
public JsonString getAsString() { throw new JsonException("Not a JSON string") ; }
public JsonNumber getAsNumber() { throw new JsonException("Not a JSON number") ; }
public JsonValue build() { if ( builtValue == null ) { if ( objects.isEmpty() && arrays.isEmpty() ) throw new JsonException("Alignment error: no object or array started") ; throw new JsonException("Alignment error: unfinished outer object or array") ; } return builtValue ; }
public JsonValue build() { if ( builtValue == null ) { if ( objects.isEmpty() && arrays.isEmpty() ) throw new JsonException("Alignment error: no object or array started") ; throw new JsonException("Alignment error: unfinished outer object or array") ; } return builtValue ; }
public JsonBuilder key(String key) { State state = stack.peek() ; if ( state != State.OBJECT ) throw new JsonException("JSON build error : not in an object") ; keys.push(key) ; return this ; }
public JsonBuilder key(String key) { State state = stack.peek() ; if ( state != State.OBJECT ) throw new JsonException("JSON build error : not in an object") ; keys.push(key) ; return this ; }
public JsonBuilder finishArray() { if ( stack.isEmpty() ) throw new JsonException("Alignment error : already built outer-most object or array") ; State state = stack.pop() ; if ( state != State.ARRAY ) throw new JsonException("JSON build error : not in an array") ; JsonValue value = arrays.pop() ; maybeObjectOrArray(value) ; if ( stack.isEmpty() ) builtValue = value ; return this ; }
public JsonBuilder finishObject(String finishMarker) { if ( stack.isEmpty() ) throw new JsonException("Alignment error : already built outer-most object or array") ; State state = stack.pop() ; if ( state != State.OBJECT ) throw new JsonException("JSON build error : not in an object") ; JsonValue value = objects.pop() ; maybeObjectOrArray(value) ; if ( stack.isEmpty() ) builtValue = value ; String startMarker = markers.pop(); if ( ! Objects.equals(startMarker, finishMarker) ) throw new JsonException("JSON build error : start/finish alignment error: start="+startMarker+" finish="+finishMarker) ; return this ; }
private void finishCompound( String opener, String closer ) { if (openerStack.isEmpty()) throw new JsonException("cannot finish with '" + closer + "' at top level." ); String x = openerStack.pop(); if (!x.equals(opener)) throw new JsonException( "cannot finish with '" + closer + "' inside '" + x + "'." ); out.print( closer ); needsComma = true; }
public JsonBuilder finishArray() { if ( stack.isEmpty() ) throw new JsonException("Alignment error : already built outer most object or array") ; State state = stack.pop() ; if ( state != State.ARRAY ) throw new JsonException("JSON build error : not in an array") ; JsonValue value = arrays.pop() ; maybeObjectOrArray(value) ; if ( stack.isEmpty() ) builtValue = value ; return this ; }
public JsonBuilder finishObject(String finishMarker) { if ( stack.isEmpty() ) throw new JsonException("Alignment error : already built outer most object or array") ; State state = stack.pop() ; if ( state != State.OBJECT ) throw new JsonException("JSON build error : not in an object") ; JsonValue value = objects.pop() ; maybeObjectOrArray(value) ; if ( stack.isEmpty() ) builtValue = value ; String startMarker = markers.pop(); if ( ! Lib.equal(startMarker, finishMarker) ) throw new JsonException("JSON build error : start/finish alignment error: start="+startMarker+" finish="+finishMarker) ; return this ; }
private void comma() { if (needsComma) { if (openerStack.isEmpty()) throw new JsonException( "cannot have more than one element at top-level." ); out.print( ", " ); } needsComma = true; }
public static JsonValue accessPath(JsonValue obj, String... path) { for ( String p : path ) { if ( !obj.isObject() ) { throw new JsonException("Path traverses non-object") ; } obj = obj.getAsObject().get(p) ; } return obj ; }
public static JsonValue accessPath(JsonValue obj, String ... path) { for ( int i = 0 ; i < path.length ; i++ ) { String p = path[i] ; if ( ! obj.isObject() ) throw new JsonException("Path traverses non-object") ; obj = obj.getAsObject().get(p) ; } return obj ; }
public static JsonValue access(JsonValue obj, Object... path) { for ( Object p : path ) { if ( p instanceof String ) { if ( !obj.isObject() ) { throw new JsonException("Path traverses non-object") ; } obj = obj.getAsObject().get((String)p) ; } if ( p instanceof Integer ) { if ( !obj.isArray() ) { throw new JsonException("Path traverses non-array") ; } obj = obj.getAsArray().get((Integer)p) ; } } return obj ; }