@Override public Set<String> keySet() { return obj.keySet(); }
@Override public Set<String> keySet() { return obj.keySet(); }
@Override public Set<String> getFields(Object json) { return ((JSONObject) json).keySet(); }
private static JSONObject cleanUpEmbeddedJson(JSONObject obj) { if (obj != null) { for (String k : obj.keySet()) { if (k.startsWith(SerializationParts.EMBEDDED_JSON)) { obj.put(k, null); } } } return obj; }
private Map<String, Object> asMap(JSONObject jsonObj) { Map<String, Object> retval = new HashMap<String, Object>(); for (String key : jsonObj.keySet()) { JSONValue value = jsonObj.get(key); retval.put(key, fromJsonValue(value)); } return retval; }
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; } }
private static Map<String, JSONValue> readPropertiesFromJson(String jsonProperties) { Map<String, JSONValue> result = new HashMap<>(); JSONValue parsed = JSONParser.parseStrict(jsonProperties); JSONObject jsonObj = parsed.isObject(); if (jsonObj != null) { for (String key : jsonObj.keySet()) { JSONValue jsonValue = jsonObj.get(key); result.put(key, jsonValue); } } return result; } }
public final Map<String, Integer> getStringIntMap(String key) { if (!hasKey(key)) { return null; } Map<String, Integer> map = new HashMap<String, Integer>(); JSONObject object = new JSONObject(this); JSONObject value = (JSONObject) object.get(key); Set<String> keys = value.keySet(); for (String string : keys) { JSONNumber jValue = value.get(string).isNumber(); map.put(string, Double.valueOf(jValue.doubleValue()).intValue()); } return map; }
public final Map<String, String> getStringStringMap(String key) { if (!hasKey(key)) { return null; } Map<String, String> map = new HashMap<String, String>(); JSONObject object = new JSONObject(this); JSONObject value = (JSONObject) object.get(key); Set<String> keys = value.keySet(); for (String string : keys) { JSONString jValue = value.get(string).isString(); map.put(string, jValue.stringValue()); } return map; }
public final PlaceRequest toPlaceRequest() { JSONObject rawParams = new JSONObject(getParams()); Map<String, String> params = new HashMap<String, String>(); for (String key : rawParams.keySet()) { params.put(key, rawParams.get(key).isString().stringValue()); } return new DefaultPlaceRequest(getIdentifier(), params); } }
public Map<String, OutputData> decodeOutputs(JSONValue json) throws FormEncodingException { Map<String, OutputData> retval = new HashMap<String, OutputData>(); if (json != null && json.isObject() != null) { for (String key : json.isObject().keySet()) { JSONValue value = json.isObject().get(key); if (value.isObject() != null) { JSONObject jsonObj = value.isObject(); retval.put(key, (OutputData) decode(asMap(jsonObj))); } } } return retval; }
public Map<String, InputData> decodeInputs(JSONValue json) throws FormEncodingException { Map<String, InputData> retval = new HashMap<String, InputData>(); if (json != null && json.isObject() != null) { for (String key : json.isObject().keySet()) { JSONValue value = json.isObject().get(key); if (value.isObject() != null) { JSONObject jsonObj = value.isObject(); retval.put(key, (InputData) decode(asMap(jsonObj))); } } } return retval; }
static ColumnSet fromJson(String json) { try { JSONObject jsonObject = JSONParser.parseStrict(json).isObject(); int rowsCount = (int) jsonObject.get("rows").isNumber().doubleValue(); Map<String, ColumnView> views = Maps.newHashMap(); JSONObject jsonColumns = jsonObject.get("columns").isObject(); for (String columnId : jsonColumns.keySet()) { views.put(columnId, parseColumn(rowsCount, jsonColumns.get(columnId).isObject())); } return new ColumnSet(rowsCount, views); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to parse column set: " + e.getMessage() + "\n" + json, e); throw e; } }
@Override public Map<K, V> deserialize(final JSONValue jsonValue) { if (jsonValue == null || jsonValue.isNull() != null) { return null; } final JSONObject jsonObject = jsonValue.isObject(); if (jsonObject == null) { throw new GWTPojoSerializerException("Unable to deserialize " + jsonValue.toString() + " as Map<?, ?>"); } final Map<K, V> map = new HashMap<K, V>(); for (String keyString : jsonObject.keySet()) { final K key = kSerializer.deserialize(new JSONString(keyString)); final V value = vSerializer.deserialize(jsonObject.get(keyString)); map.put(key, value); } return map; } }
public static JavaCoreOptionsDto fromJson(JSONValue jsonVal) { if (jsonVal == null) { return null; } JSONObject json= jsonVal.isObject(); JavaCoreOptionsDto result= new JavaCoreOptionsDto(); JSONValue jsonoptionsJson = json.get("options"); if (jsonoptionsJson != null && !(jsonoptionsJson.isNull() != null)) { java.util.Map<java.lang.String, java.lang.String> jsonoptionsVal= new HashMap<String, java.lang.String>(); JSONObject jsonoptionsValo = jsonoptionsJson.isObject(); for(String jsonoptionsValok : jsonoptionsValo.keySet()) { java.lang.String jsonoptionsValoX = jsonoptionsValo.get(jsonoptionsValok).isString().stringValue();; jsonoptionsVal.put(jsonoptionsValok, jsonoptionsValoX); } result.setOptions((java.util.Map<java.lang.String, java.lang.String>)jsonoptionsVal); } return result; } }
private LayoutDragComponent getLayoutDragComponent(JSONObject jsonObject, String type) { LayoutDragComponent dragComponent = getLayoutDragComponent(type); if (dragComponent instanceof HasDragAndDropSettings) { HasDragAndDropSettings sComponent = (HasDragAndDropSettings) dragComponent; JSONObject params = jsonObject.get(COMPONENT_PARAMS).isObject(); if (params != null) { for (String key : params.keySet()) { JSONString value = params.get(key).isString(); if (value != null) { sComponent.setSettingValue(key, value.stringValue()); } } } } return dragComponent; }
private LayoutDragComponent getLayoutDragComponent(JSONObject jsonObject, String type) { LayoutDragComponent dragComponent = getLayoutDragComponent(type); if (dragComponent instanceof HasDragAndDropSettings) { HasDragAndDropSettings sComponent = (HasDragAndDropSettings) dragComponent; JSONObject params = jsonObject.get(COMPONENT_PARAMS).isObject(); if (params != null) { for (String key : params.keySet()) { JSONString value = params.get(key).isString(); if (value != null) { sComponent.setSettingValue(key, value.stringValue()); } } } } return dragComponent; }
private String extractFailure(final JSONObject response) { String failure = "n/a"; JSONValue failureValue = response.get(FAILURE_DESCRIPTION); if (failureValue.isString() != null) { failure = failureValue.isString().stringValue(); } else if (failureValue.isObject() != null) { JSONObject failureObject = failureValue.isObject(); for (String key : failureObject.keySet()) { if (key.contains("failure") && failureObject.get(key).isString() != null) { failure = failureObject.get(key).isString().stringValue(); break; } } } return failure; }
public static void fire(HasDataSelectionEventHandlers source, Object sender, JavaScriptObject data) { DataSelectionEvent event = new DataSelectionEvent(sender); JSONObject array = new JSONObject(data); event.series = new LinkedList<Series>(); for(String key : array.keySet()){ JSONObject obj = array.get(key).isObject(); if(obj != null){ Series series1 = JavaScriptObject.createObject().cast(); series1.setValue(obj.get("value").isNumber().doubleValue()); series1.setColor(obj.get("fillColor").isString().stringValue()); event.series.add(series1); } } source.fireEvent(event); }
/** * Used to deserialize the bindings once on the client. Usage of GWT code is allowed. */ public RestParameterBindings deserialize(String encodedParameters) { RestParameterBindings parameters = new RestParameterBindings(); JSONObject json = JSONParser.parseStrict(encodedParameters).isObject(); for (String method : json.keySet()) { HttpMethod httpMethod = HttpMethod.valueOf(method); JSONArray jsonParameters = json.get(method).isArray(); for (int i = 0; i < jsonParameters.size(); ++i) { HttpParameter parameter = deserialize(jsonParameters.get(i).isObject()); parameters.put(httpMethod, parameter); } } return parameters; }