}
public static String getString(JSONObject json, String field) {
- JSONValue jsonValue;
- JSONString jsonString;
- if ((jsonValue = json.get(field)) == null) {
- return null;
- }
- if ((jsonString = jsonValue.isString()) == null) {
- JSONNumber jsonNumber = jsonValue.isNumber();
- return jsonNumber != null ? jsonNumber.toString() : null;
- }
- return jsonString.stringValue();
+ return getAsString(json.get(field));
}
public static Date getDate(JSONObject json, String field) {
throw new JavaScriptException("Not implemented");
}
+ public static String getAsString(JSONValue jsonValue) {
+ if (jsonValue == null) {
+ return null;
+ }
+ JSONString jsonString;
+ if ((jsonString = jsonValue.isString()) == null) {
+ JSONNumber jsonNumber = jsonValue.isNumber();
+ return jsonNumber != null ? jsonNumber.toString() : null;
+ }
+ return jsonString.stringValue();
+ }
+
/**
* @since 2.5
*/
package org.sonar.wsclient.gwt.unmarshallers;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.json.client.*;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONValue;
import org.sonar.gwt.JsonUtils;
import org.sonar.wsclient.services.TimeMachineData;
Map<Date, List<String>> data = new HashMap<Date, List<String>>();
for (String dateTimeStr : map.keySet()) {
JSONArray array = map.get(dateTimeStr).isArray();
- List<String> values = new ArrayList<String>();
+ List<String> measures = new ArrayList<String>();
for (int i = 0; i < JsonUtils.getArraySize(array); i++) {
- JSONValue elem = array.get(i);
- values.add(getAsString(elem));
+ JSONValue elem = JsonUtils.getArray(array, i);
+ measures.add(JsonUtils.getAsString(elem));
}
- data.put(JsonUtils.parseDateTime(dateTimeStr), values);
+ data.put(JsonUtils.parseDateTime(dateTimeStr), measures);
}
return new TimeMachineData().setData(data);
}
- public String getAsString(JSONValue jsonValue) {
- if (jsonValue == null) {
- return null;
- }
- JSONString jsonString;
- if ((jsonString = jsonValue.isString()) == null) {
- JSONNumber jsonNumber = jsonValue.isNumber();
- return jsonNumber != null ? jsonNumber.toString() : null;
- }
- return jsonString.stringValue();
- }
-
public List<TimeMachineData> toModels(JavaScriptObject json) {
return Arrays.asList(toModel(json));
}
Map<Date, List<String>> data = new HashMap<Date, List<String>>();
for (Object key : map.keySet()) {
JSONArray array = (JSONArray) map.get(key);
- List<String> values = new ArrayList<String>();
+ List<String> measures = new ArrayList<String>();
for (int i = 0; i < array.size(); i++) {
Object elem = array.get(i);
String value = elem == null ? null : elem.toString();
- values.add(value);
+ measures.add(value);
}
- data.put(JsonUtils.parseDateTime((String) key), values);
+ data.put(JsonUtils.parseDateTime((String) key), measures);
}
return new TimeMachineData().setData(data);
}