Refine search
public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
/** * Evaluates a JSON string and returns its JSONValue representation. The * browser's {@code JSON.parse function} is used. * * @param jsonString a JSON object to parse * @return a JSONValue that has been built by parsing the JSON string * @throws NullPointerException if <code>jsonString</code> is <code>null</code> * @throws IllegalArgumentException if <code>jsonString</code> is empty */ public static JSONValue parseStrict(String jsonString) { return parse(jsonString, true); }
@Override public void onSuccess(UserVerifierDto key) { String jsonConfig = key.getJsonConfiguration(); JSONObject json; //Some verifiers (ex:Trustful) has no jsonConfiguration field if (jsonConfig != null && !jsonConfig.isEmpty()) { json = (JSONObject) JSONParser.parseLenient(jsonConfig); } else { json = new JSONObject(); } json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
private static Map<String, JSONValue> readPreferencesFromJson(String jsonPreferences) { Map<String, JSONValue> result = new HashMap<>(); JSONValue parsed = JSONParser.parseStrict(jsonPreferences); JSONObject jsonObj = parsed.isObject(); if (jsonObj != null) { jsonObj.keySet().forEach(key -> result.put(key, jsonObj.get(key))); } return result; } }
@SuppressWarnings("unchecked") @Override protected T parseResult() throws Exception { try { JSONValue val = JSONParser.parseStrict(response.getText()); if (val.isObject() != null) { return (T) val.isObject().getJavaScriptObject(); } else if (val.isArray() != null) { return (T) val.isArray().getJavaScriptObject(); } else { throw new ResponseFormatException("Response was NOT a JSON object"); } } catch (JSONException e) { throw new ResponseFormatException("Response was NOT a valid JSON document", e); } catch (IllegalArgumentException e) { throw new ResponseFormatException("Response was NOT a valid JSON document", e); } } });
if ((obj = val.isObject()) != null) { JSONValue encType = obj.get(ENCODED_TYPE); JSONValue objectIdVal = obj.get(OBJECT_ID); if (objectIdVal != null && encType != null) { String objectId = objectIdVal.isString().stringValue(); String cacheKey = objectId + "/" + encType.isString().stringValue(); if (!objectId.equals("-1")) { JSONValue backRef = objectCache.get(cacheKey); if (parent != null) { obj = backRef.isObject(); parent.put(key, obj); final JSONValue newKey = JSONParser.parseStrict((k.substring(SerializationParts.EMBEDDED_JSON.length()))); JSONValue value = obj.get(k); JSONObject tmpObject = new JSONObject();
@Override public FormRepresentation decode(String code) throws FormEncodingException { FormRepresentation form = new FormRepresentation(); JSONValue json = JSONParser.parseLenient(code); if (json.isObject() != null) { JSONObject jsonObj = json.isObject(); if (jsonObj.get("action").isString() != null) { form.setAction(jsonObj.get("action").isString().stringValue()); if (jsonObj.get("documentation").isString() != null) { form.setDocumentation(jsonObj.get("documentation").isString() .stringValue());
JSONObject jsonRoot = null; if (data instanceof JavaScriptObject) { jsonRoot = new JSONObject((JavaScriptObject) data); } else { jsonRoot = (JSONObject) JSONParser.parse((String) data); JSONArray root = (JSONArray) jsonRoot.get(modelType.getRoot()); int size = root.size(); ArrayList<ModelData> models = new ArrayList<ModelData>(); Class type = field.getType(); String map = field.getMap() != null ? field.getMap() : field.getName(); JSONValue value = obj.get(map); if (value.isArray() != null) { } else if (value.isBoolean() != null) { model.set(name, value.isBoolean().booleanValue()); } else if (value.isNumber() != null) { if (type != null) {
public JSONObject parseStringToJSON(String jsonString) { JSONObject json = null; try { json = JSONParser.parseStrict(jsonString).isObject(); } catch (Exception ex) { GWT.log("this json " + jsonString + " is not parsed", ex); } return json; }
assertNotNull(json); JSONValue jsonValue = JSONParser.parseStrict(json); assertNotNull(jsonValue); JSONObject jsonObject = jsonValue.isObject(); assertNotNull(jsonObject); assertTrue(jsonObject.containsKey("booleanPrimitive")); assertNotNull(jsonObject.get("booleanPrimitive").isBoolean()); assertFalse(jsonObject.get("booleanPrimitive").isBoolean().booleanValue()); assertTrue(jsonObject.containsKey("booleanObject")); assertSame(JSONNull.getInstance(), jsonObject.get("booleanObject").isNull());
public void initToken( String token ) { try { values = JSONParser.parseStrict( token ).isObject(); } catch( Exception e ) { values = new JSONObject(); } }
@Override public ModelNode get() { ModelNode node; if (contentType.startsWith(APPLICATION_DMR_ENCODED)) { node = ModelNode.fromBase64(payload); } else if (contentType.startsWith(APPLICATION_JSON)) { node = new ModelNode(); JSONObject response = JSONParser.parseLenient(payload).isObject(); JSONString outcome = response.get(OUTCOME).isString(); node.get(OUTCOME).set(outcome.stringValue()); if (outcome.stringValue().equals(SUCCESS)) { if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) { node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2)); } else { node.get(RESULT).set(new ModelNode()); } } else { String failure = extractFailure(response); node.get(FAILURE_DESCRIPTION).set(failure); } } else { node = new ModelNode(); node.get(OUTCOME).set(FAILED); node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType); } return node; }
@Override public T decode(String value) throws DecodingException { try { return decode(JSONParser.parseStrict(value)); } catch (JSONException e) { // that can happen for generic key types like Object and then a String key gets passed in return decode(JSONParser.parseStrict("\"" + value + "\"")); } }
if (code == Response.SC_OK) { clearError(); callback.got(JSONParser.parse(response.getText())); return; } else if (code >= Response.SC_BAD_REQUEST) { // 400+ => Oops. final JSONValue json = JSONParser.parse(err); final JSONObject result = json == null ? null : json.isObject(); final JSONValue jerr = result == null ? null : result.get("err"); final JSONString serr = jerr == null ? null : jerr.isString(); err = serr.stringValue();
classAttributeMetadatas = filterListAttributes(classAttributeMetadatas); final JSONArray array = (JSONArray)JSONParser.parseStrict(content); for (AttributeMetadata classAttributeMetadata : classAttributeMetadatas) JSONValue jvalue = ((JSONObject)array.get(row)).get(classAttributeMetadata.getName()); if (jvalue != null) String svalue = jvalue.isString().stringValue(); Widget w = readOnlyValue(classAttributeMetadata, svalue); table.setWidget(row, col, w);
public JSONObject getJSON(){ JSONObject json = new JSONObject(); JSONValue top = JSONParser.parse(String.valueOf(this.getTop())); JSONValue left = JSONParser.parse(String.valueOf(this.getLeft())); JSONValue right = JSONParser.parse(String.valueOf(this.getRight())); JSONValue bottom = JSONParser.parse(String.valueOf(this.getBottom())); json.put("top", top); json.put("left", left); json.put("right", right); json.put("bottom", bottom); return json; }
updateChildren = new ArrayList<ServerConnector>(getChildren()); if (getState().customMapOptionsJson != null) { options = JSONParser.parseStrict(getState().customMapOptionsJson).isObject().getJavaScriptObject().cast(); } else { options = MapOptions.create();
@Override public void onSuccess(LogAppenderDto key) { JSONObject json = (JSONObject) JSONParser.parseLenient(key.getJsonConfiguration()); json.put("minLogSchemaVersion", new JSONNumber(key.getMinLogSchemaVersion())); json.put("maxLogSchemaVersion", new JSONNumber(key.getMaxLogSchemaVersion())); json.put("pluginTypeName", new JSONString(key.getPluginTypeName())); json.put("pluginClassName", new JSONString(key.getPluginClassName())); JSONArray headersStructure = new JSONArray(); for (LogHeaderStructureDto header : key.getHeaderStructure()) { headersStructure.set(headersStructure.size(), new JSONString(header.getValue())); } json.put("headerStructure", headersStructure); ServletHelper.downloadJsonFile(json.toString(), key.getPluginTypeName() + ".json"); } };
public void onResponseReceived(final com.google.gwt.http.client.Request r, final com.google.gwt.http.client.Response response) { if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK) { final JSONValue json = JSONParser.parse(response.getText()); if (json != null && json.isArray() != null) { final JSONArray results = json.isArray(); final int n = Math.min(request.getLimit(), results.size()); for (int i = 0; i < n; i++) { final JSONValue suggestion = results.get(i); if (suggestion == null || suggestion.isString() == null) { continue;
JSONObject value = (JSONObject)JSONParser.parseStrict(content); JSONArray array = (JSONArray)value.get("result");