private JettisonObjectIterator(org.codehaus.jettison.json.JSONObject jsonObject) { this.jsonObject = jsonObject; this.jsonKeysIt = jsonObject.keys(); }
@Override public boolean hasNext() { return index < jsonArray.length(); }
protected JSONArray addContactData(final HttpServletRequest request) throws JSONException { final JSONArray contactList = new JSONArray(); final JSONObject contact = new JSONObject(); contact.put("@type", "ContactPoint"); contact.put("telephone", getSiteCustomerServiceNumber()); contact.put("contactType", "customerService"); extensionManager.getProxy().addContactData(request, contact); contactList.put(contact); return contactList; }
@Override protected JSONArray getLinkedDataJsonInternal(final String url, final HttpServletRequest request, final JSONArray schemaObjects) throws JSONException { final JSONObject categoryData = new JSONObject(); categoryData.put("@context", getStructuredDataContext()); categoryData.put("@type", "ItemList"); addCategoryProductData(request, categoryData); extensionManager.getProxy().addCategoryData(request, categoryData); schemaObjects.put(categoryData); return schemaObjects; }
private JSONObject createJson( String primaryEndpoint, String dataCenter, String rack, String status, String state, String load, String owns, String token) throws JSONException { JSONObject object = new JSONObject(); object.put("endpoint", primaryEndpoint); object.put("dc", dataCenter); object.put("rack", rack); object.put("status", status); object.put("state", state); object.put("load", load); object.put("owns", owns); object.put("token", token); return object; }
private void getIdentityDocument() throws JSONException { if (this.identityDocument == null) { String jsonStr = SystemUtils.getDataFromUrl( "http://169.254.169.254/latest/dynamic/instance-identity/document"); this.identityDocument = new JSONObject(jsonStr); } }
@Override public int length(Object obj) { if( obj instanceof org.codehaus.jettison.json.JSONArray ) { return ((org.codehaus.jettison.json.JSONArray) obj).length(); } if( obj instanceof org.codehaus.jettison.json.JSONObject ) { return ((org.codehaus.jettison.json.JSONObject)obj).length(); } if( obj instanceof String ) { return ((String)obj).length(); } return 0; }
@Override public String toJson(Object obj) { try { if( obj instanceof org.codehaus.jettison.json.JSONArray ) { return ((org.codehaus.jettison.json.JSONArray)obj).toString(2); } if( obj instanceof org.codehaus.jettison.json.JSONObject ) { return ((org.codehaus.jettison.json.JSONObject)obj).toString(2); } return String.valueOf(obj); //return "\"" + String.valueOf(obj).replaceAll("\"", "\\\"") + "\""; } catch( org.codehaus.jettison.json.JSONException jsonException ) { throw new IllegalStateException(jsonException); } }
@Override public void setProperty(Object obj, Object key, Object value) { try { if( obj instanceof org.codehaus.jettison.json.JSONArray ) { int index = key instanceof Integer? (Integer) key : Integer.parseInt(key.toString()); ((org.codehaus.jettison.json.JSONArray)obj).put(index, jettisonWrap(value)); } if( obj instanceof org.codehaus.jettison.json.JSONObject ) { ((org.codehaus.jettison.json.JSONObject)obj).put(String.valueOf(key), jettisonWrap(value)); } } catch( org.codehaus.jettison.json.JSONException jsonException ) { throw new IllegalStateException(jsonException); } }
@Override public String getRegion() { try { getIdentityDocument(); return this.identityDocument.getString("region"); } catch (JSONException e) { // If there is any issue in getting region, use AZ as backup. return getRac().substring(0, getRac().length() - 1); } }
@Override public void setArrayIndex(Object array, int index, Object value) { if( !isArray(array) ) { throw new UnsupportedOperationException(); } try { ((org.codehaus.jettison.json.JSONArray)array).put(index, jettisonWrap(value)); } catch( org.codehaus.jettison.json.JSONException jsonException ) { throw new IllegalArgumentException(jsonException); } }
@Override public Object getMapValue(Object obj, String key) { Object value = ((org.codehaus.jettison.json.JSONObject)obj).opt(key); if( value==null ) { return com.jayway.jsonpath.spi.json.JsonProvider.UNDEFINED; } return jettisonUnwrap(value); }
@Override public Object getArrayIndex(Object obj, int index) { return jettisonUnwrap(((org.codehaus.jettison.json.JSONArray)obj).opt(index)); }
private static void setList(JSONWriter writer, ListColumnVector vector, TypeDescription schema, int row) throws JSONException { writer.array(); int offset = (int) vector.offsets[row]; TypeDescription childType = schema.getChildren().get(0); for (int i = 0; i < vector.lengths[row]; ++i) { setValue(writer, vector.child, childType, offset + i); } writer.endArray(); }
protected void addCategoryProductData(final HttpServletRequest request, final JSONObject categoryData) throws JSONException { final List<Product> products = getProducts(request); final JSONArray itemList = new JSONArray(); for (int i = 0; i < products.size(); i++) { JSONObject item = new JSONObject(); item.put("@type", "ListItem"); item.put("position", i + 1); item.put("url", products.get(i).getUrl()); itemList.put(item); extensionManager.getProxy().addCategoryProductData(request, categoryData); } categoryData.put("itemListElement", itemList); }
private JSONObject readAllIntoJSONObject(InputStream content) throws IOException, JSONException { BufferedReader rd = new BufferedReader(new InputStreamReader(content, StandardCharsets.UTF_8)); String jsonText = IOUtils.toString(rd); return new JSONObject(jsonText); }
@Override protected JSONArray getLinkedDataJsonInternal(final String url, final HttpServletRequest request, final JSONArray schemaObjects) throws JSONException { final Product product = getProduct(request); if (product != null) { final JSONObject productData = addProductData(request, product, url); addReviewData(request, product, productData); schemaObjects.put(productData); } return schemaObjects; }
private JSONObject readAllIntoJSONObject(InputStream content) throws IOException, JSONException { BufferedReader rd = new BufferedReader(new InputStreamReader(content, StandardCharsets.UTF_8)); String jsonText = IOUtils.toString(rd); return new JSONObject(jsonText); }