AddIndicatorDataHandler extends RestActionHandler { protected Map<String, IndicatorValue> parseIndicatorData(String data) throws ActionException { try { Map<String, Double> values = MAPPER.readValue(data, new TypeReference<Map<String, Double>>(){}); return values.entrySet().stream() .collect(Collectors .toMap( e -> e.getKey(), e -> new IndicatorValueFloat(e.getValue()))); } catch (IOException e) { throw new ActionParamsException("Invalid parameter value for key: " + PARAM_DATA + " - expected JSON object"); } }  @Override void init(); void handlePost(ActionParameters params);  }
@Test public void testParseIndicatorData() throws Exception { AddIndicatorDataHandler h = new AddIndicatorDataHandler(); Map<String, IndicatorValue> values = h.parseIndicatorData("{\"region\": 0.3}"); assertNotNull("Values shouldn't be null", values); assertEquals("Should have one value", 1, values.size()); JSONObject test = new JSONObject(); values.get("region").putToJSONObject(test, "testKey"); assertEquals("Should have one value", "0.3", test.optString("testKey")); }