JsonUnmarshaller implements Unmarshaller { @Override public Map<String, Object> unmarshal(InputStream in) { JsonReader reader = Json.createReader(in); JsonObject jsonO = reader.readObject(); HashMap<String, Object> map = new HashMap<>(); for (String key : jsonO.keySet()) { map.put(key, unmarshalAttribute(jsonO.get(key))); } reader.close(); return map; }  @Override Map<String, Object> unmarshal(InputStream in);  }
@Test public void testRead() throws IOException { URL url = this.getClass().getResource("/metrics.json"); URLConnection connection = url.openConnection(); InputStream is = connection.getInputStream(); JsonUnmarshaller marshaller = new JsonUnmarshaller(); Map<String, Object> map = marshaller.unmarshal(is); BigDecimal load = (BigDecimal)map.get("systemload.average"); Assert.assertEquals(new BigDecimal(0.61d, new MathContext(2)), load); Assert.assertEquals(256000, ((Long)map.get("heap.init")).longValue()); @SuppressWarnings("unchecked") Map<String, Object> mdc = (Map<String, Object>)map.get("MDC"); Assert.assertNotNull("MDC shouldn't be null", mdc); Assert.assertEquals("some test", mdc.get("testMDC")); Assert.assertEquals(1, mdc.size()); @SuppressWarnings("unchecked") List<Object> list = (List<Object>)map.get("sampleList"); Assert.assertNotNull("List shouldn't be null", list); Assert.assertEquals(2, list.size()); Assert.assertEquals(3L, list.get(0)); Assert.assertEquals("Hello", list.get(1)); System.out.println(map); }