use of com.google.gwt.json.client.JSONValue in project gwt-test-utils by gwt-test-utils.
the class JSONObjectParser method getInnerMap.
private static Map<String, JSONValue> getInnerMap(JSONObject jsonObject) {
JavaScriptObject jsObject = jsonObject.getJavaScriptObject();
Map<String, JSONValue> map = JavaScriptObjects.getObject(jsObject, JSONOBJECT_MAP);
if (map == null) {
map = new LinkedHashMap<String, JSONValue>();
JavaScriptObjects.setProperty(jsObject, JSONOBJECT_MAP, map);
}
return map;
}
use of com.google.gwt.json.client.JSONValue in project perun by CESNET.
the class JsonUtils method parseJsonToMap.
/**
* Parses a JavaScript map into a Java map.
* @param jso
* @return
*/
public static final Map<String, JSONValue> parseJsonToMap(JavaScriptObject jso) {
if (jso == null) {
// when null, return empty map
return new HashMap<String, JSONValue>();
}
JSONObject obj = new JSONObject(jso);
HashMap<String, JSONValue> m = new HashMap<String, JSONValue>();
for (String key : obj.keySet()) {
m.put(key, obj.get(key));
}
return m;
}
use of com.google.gwt.json.client.JSONValue in project perun by CESNET.
the class AddUserExtSource method prepareJSONObject.
/**
* Prepares a JSON object
*
* @return JSONObject the whole query
*/
private JSONObject prepareJSONObject() {
JSONNumber user = new JSONNumber(userId);
// create Json object from webgui extSource
JSONObject oldExtSource = new JSONObject(extSource);
// get only interested in items
JSONValue uesName = oldExtSource.get("name");
JSONValue uesId = oldExtSource.get("id");
JSONValue uesType = oldExtSource.get("type");
// create a new form of ext source
JSONObject newExtSource = new JSONObject();
newExtSource.put("name", uesName);
newExtSource.put("id", uesId);
newExtSource.put("type", uesType);
// create new userExtSource
JSONObject userExtSource = new JSONObject();
userExtSource.put("id", new JSONNumber(0));
userExtSource.put("extSource", newExtSource);
userExtSource.put("login", new JSONString(login));
userExtSource.put("loa", new JSONNumber(loa));
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("user", user);
jsonQuery.put("userExtSource", userExtSource);
return jsonQuery;
}
use of com.google.gwt.json.client.JSONValue in project perun by CESNET.
the class SetAttributes method prepareJSONObject.
/**
* Prepares a JSON object.
* @return JSONObject the whole query
*/
private JSONObject prepareJSONObject() {
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
// create attrs field
JSONArray array = new JSONArray();
// create attributes
for (int i = 0; i < attributes.size(); i++) {
// skip attribute with empty or null value
if (attributes.get(i).getValue() == null || attributes.get(i).getValue().equalsIgnoreCase("")) {
continue;
}
// create Json object from attribute
JSONObject attr = new JSONObject(attributes.get(i));
// get only interested in properties
JSONValue id = attr.get("id");
JSONValue friendlyName = attr.get("friendlyName");
JSONValue namespace = attr.get("namespace");
JSONValue type = attr.get("type");
JSONValue description = attr.get("description");
JSONValue value = attr.get("value");
JSONValue displayName = attr.get("displayName");
// create new Attribute jsonObject
JSONObject newAttr = new JSONObject();
newAttr.put("value", value);
newAttr.put("id", id);
newAttr.put("type", type);
newAttr.put("description", description);
newAttr.put("namespace", namespace);
newAttr.put("friendlyName", friendlyName);
newAttr.put("displayName", displayName);
// put attribute into array
array.set(array.size(), newAttr);
}
for (Map.Entry<String, Integer> attrIds : this.ids.entrySet()) {
jsonQuery.put(attrIds.getKey(), new JSONNumber(attrIds.getValue()));
}
jsonQuery.put("attributes", array);
return jsonQuery;
}
use of com.google.gwt.json.client.JSONValue in project GwtMobile by dennisjzh.
the class BluetoothUi method listDevices.
public void listDevices() {
Bluetooth.listDevices(new StringCallback() {
@Override
public void onSuccess(String result) {
try {
String textHTML = "";
JSONValue value = JSONParser.parseLenient(result);
JSONArray devicesArray = value.isArray();
if (devicesArray != null) {
textHTML = "Result:";
for (int i = 0; i < devicesArray.size(); i++) {
JSONObject deviceObj = devicesArray.get(i).isObject();
textHTML = textHTML + "<br/>" + deviceObj.get("name");
}
text.setHTML(textHTML);
}
} catch (Exception e) {
e.printStackTrace();
text.setHTML("Error: " + e.getMessage());
}
}
@Override
public void onError(String message) {
text.setHTML("Error: " + message);
}
});
}
Aggregations