Java Code Examples for javax.json.JsonValue.ValueType#OBJECT
The following examples show how to use
javax.json.JsonValue.ValueType#OBJECT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkConfig.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
private static List<JsonObject> getJsonValueAsList(JsonValue value) { if (value != null) { if (value.getValueType() == ValueType.ARRAY) { return value.asJsonArray().getValuesAs(JsonObject.class); } else if (value.getValueType() == ValueType.OBJECT) { List<JsonObject> ret = new ArrayList<>(); ret.add(value.asJsonObject()); return ret; } } return null; }
Example 2
Source File: NetworkConfig.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
private static JsonObject getJsonObject(JsonObject object, String propName) { JsonObject obj = null; JsonValue val = object.get(propName); if (val != null && val.getValueType() == ValueType.OBJECT) { obj = val.asJsonObject(); } return obj; }
Example 3
Source File: JSONContentHandler.java From jcypher with Apache License 2.0 | 5 votes |
@Override public Object convertContentValue(Object value) { if (value instanceof JsonValue) { JsonValue val = (JsonValue) value; Object ret = null; ValueType typ = val.getValueType(); if (typ == ValueType.NUMBER) ret = ((JsonNumber)val).bigDecimalValue(); else if (typ == ValueType.STRING) ret = ((JsonString)val).getString(); else if (typ == ValueType.FALSE) ret = Boolean.FALSE; else if (typ == ValueType.TRUE) ret = Boolean.TRUE; else if (typ == ValueType.ARRAY) { JsonArray arr = (JsonArray)val; List<Object> vals = new ArrayList<Object>(); int sz = arr.size(); for (int i = 0; i < sz; i++) { JsonValue v = arr.get(i); vals.add(convertContentValue(v)); } ret = vals; } else if (typ == ValueType.OBJECT) { //JsonObject obj = (JsonObject)val; } return ret; } return value; }
Example 4
Source File: JSONContentHandler.java From jcypher with Apache License 2.0 | 5 votes |
@Override public PathInfo getPathInfo(String colKey) { PathInfo pathInfo = null; int colIdx = getColumnIndex(colKey); if (colIdx == -1) throw new RuntimeException("no result column: " + colKey); JsonObject dataObject = (JsonObject) this.jsonValue; JsonArray restArray = getRestArray(dataObject); JsonValue restValue = getRestValue(restArray, colIdx); restValue = this.handleArrayCase(restValue); if (restValue.getValueType() == ValueType.OBJECT) { JsonObject pathObject = (JsonObject) restValue; String str = pathObject.getString("start"); long startId = Long.parseLong(str.substring(str.lastIndexOf('/') + 1)); str = pathObject.getString("end"); long endId = Long.parseLong(str.substring(str.lastIndexOf('/') + 1)); JsonArray rels = pathObject.getJsonArray("relationships"); List<Long> relIds = new ArrayList<Long>(); int sz = rels.size(); for (int i = 0; i < sz; i++) { String rel = rels.getString(i); long rid = Long.parseLong(rel.substring(rel.lastIndexOf('/') + 1)); relIds.add(Long.valueOf(rid)); } pathInfo = new PathInfo(startId, endId, relIds, pathObject); } return pathInfo; }
Example 5
Source File: NetworkConfig.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
private static JsonObject getJsonValueAsObject(JsonValue value) { return (value != null && value.getValueType() == ValueType.OBJECT) ? value.asJsonObject() : null; }
Example 6
Source File: RequestCaseJson.java From tcases with MIT License | 4 votes |
/** * Returns the DataValue represented by the given JSON object. */ private static DataValue<?> asDataValue( RequestCaseContext context, JsonValue json) { DataValue<?> data; ValueType jsonType = json.getValueType(); if( jsonType == ValueType.NULL) { data = null; } else if( jsonType == ValueType.OBJECT) { JsonObject object = (JsonObject) json; String type = context.resultFor( TYPE, () -> object.getString( TYPE)); String format = context.resultFor( FORMAT, () -> object.getString( FORMAT, null)); data = context.resultFor( VALUE, () -> { return type.equals( "array")? asArrayValue( context, object.getJsonArray( VALUE)) : type.equals( "boolean")? new BooleanValue( object.getBoolean( VALUE)) : type.equals( "integer")? asIntegerValue( context, object.getJsonNumber( VALUE), format) : type.equals( "null")? new NullValue() : type.equals( "number")? new DecimalValue( object.getJsonNumber( VALUE).bigDecimalValue(), format) : type.equals( "object")? asObjectValue( context, object.getJsonObject( VALUE)) : asStringValue( context, object.getString( VALUE), format); }); } else { throw new RequestCaseException( String.format( "Invalid value type=%s -- must be either \"null\" or \"object\"", jsonType)); } return data; }