OpentsdbConverter { public static Metric convertToModel(JSONObject json) { Metric m = new Metric(); m.setTimestamp(json.getLongValue("timestamp") * 1000L); m.setName(json.getString("metric")); m.setValue(json.getDoubleValue("value")); Map<String, String> mtags = m.getTags(); JSONObject tags = json.getJSONObject("tags"); if (tags != null) { for (Map.Entry<String, Object> e : tags.entrySet()) { String key = MetricUtils.formatMetricTagKey(e.getKey()); String value = MetricUtils.formatTagValue(e.getValue().toString()); mtags.put(key, value); } } return m; } private  OpentsdbConverter(); static Metric convertToModel(JSONObject json);  }
@Test public void testConvertToModel() { Map map = new HashMap(); map.put("app", "demo"); JSONObject obj = new JSONObject(); obj.put("timestamp", 1557844146565l); obj.put("metric", "jvm.mem.free"); obj.put("value", 1.2d); obj.put("tags", map); System.out.println(JSONObject.toJSONString(obj)); Metric m = OpentsdbConverter.convertToModel(obj); System.out.println(m); Assert .assertEquals( "Metric{name='jvm.mem.free', value=1.2, timestamp=1557844146565000, info='null', tags={app=demo}}", m.toString()); }