@Test public void toMap_Nested_Array_Simple() { String str = "{\"str\":\"str\",\"int\":1,\"bool\":true,\"array\":[\"a1\",1,true]}"; Map<String, Object> map = JsonUtils.toMap(str); Assert.assertEquals("str", map.get("str")); Assert.assertEquals(String.class, map.get("str").getClass()); Assert.assertEquals(new Integer(1), map.get("int")); Assert.assertEquals(Integer.class, map.get("int").getClass()); Assert.assertEquals(new Boolean(true), map.get("bool")); Assert.assertEquals(Boolean.class, map.get("bool").getClass()); Assert.assertEquals(Object[].class, map.get("array").getClass()); Object[] array = (Object[]) map.get("array"); Assert.assertEquals(String.class, array[0].getClass()); Assert.assertEquals("a1", array[0]); Assert.assertEquals(Integer.class, array[1].getClass()); Assert.assertEquals(1, array[1]); Assert.assertEquals(Boolean.class, array[2].getClass()); Assert.assertEquals(new Boolean(true), array[2]); }
public static Map<String, Object> toMap(String json) { return getGson().fromJson(json, new TypeToken<HashMap<String, Object>>() { }.getType()); }
JsonUtils { public static Map<String, Object> toMap(String json) { return getGson().fromJson(json, new TypeToken<HashMap<String, Object>>() { }.getType()); } }
JsonUtils { public static Map<String, Object> toMap(String json) { return getGson().fromJson(json, new TypeToken<HashMap<String, Object>>() { }.getType()); } private  JsonUtils(); }
JsonUtils { public static Map<String, Object> toMap(String json) { return getGson().fromJson(json, new TypeToken<HashMap<String, Object>>() { }.getType()); } private  JsonUtils(); static String stripComment(String source); static String toJson(Object source); static Map<String, Object> toMap(String json); static Object[] toArray(String json); static Collection<T> toCollection(String json); }
JsonUtils { public static Map<String, Object> toMap(String json) { return getGson().fromJson(json, new TypeToken<HashMap<String, Object>>() { }.getType()); } private  JsonUtils(); static String stripComment(String source); static String toJson(Object source); static Map<String, Object> toMap(String json); static Object[] toArray(String json); static Collection<T> toCollection(String json);  }