diff options
-rw-r--r-- | sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java | 12 | ||||
-rw-r--r-- | sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java index b473cc37028..d3aee0fa49c 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java +++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/JsonUtils.java @@ -176,6 +176,18 @@ public final class JsonUtils { return jsonString.stringValue(); } + public static Double getAsDouble(JSONValue jsonValue) { + if (jsonValue == null) { + return null; + } + JSONNumber jsonNumber; + if ((jsonNumber = jsonValue.isNumber()) == null) { + JSONString jsonString = jsonValue.isString(); + return jsonString != null ? Double.parseDouble(jsonString.toString()) : null; + } + return jsonNumber.doubleValue(); + } + /** * @since 2.5 */ diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java index 1fddae26e76..adc79ccc582 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/TimeMachineUnmarshaller.java @@ -31,7 +31,7 @@ public class TimeMachineUnmarshaller extends AbstractUnmarshaller<TimeMachine> { for (int i = 0; i < size; i++) { JSONObject cellJson = JsonUtils.getArray(cells, i); JSONArray valuesJson = cellJson.get("v").isArray(); - Object[] resultValues = new Object[valuesJson.size()]; + Object[] resultValues = new Object[JsonUtils.getArraySize(valuesJson)]; for (int indexValue = 0; indexValue < JsonUtils.getArraySize(valuesJson); indexValue++) { Object value = valuesJson.get(indexValue); resultValues[indexValue] = value; |