@Test public void convertJsonStringToMapShouldReturnEmptyMapForEmptyJson() { String input = "{}"; Map<String, String> expected = Collections.emptyMap(); assertThat(JsonUtil.convertJsonStringToMap(input), equalTo(expected)); }
public static Map<String, String> convertJsonStringToMap(String jsonString) { if (jsonString == null || jsonString.equals("") || jsonString.equals("{}")) { return Collections.emptyMap(); } Type stringMapType = new TypeToken<Map<String, String>>() {}.getType(); return gson.fromJson(jsonString, stringMapType); }
JsonUtil { public static Map<String, String> convertJsonStringToMap(String jsonString) { if (jsonString == null || jsonString.equals("") || jsonString.equals("{}")) { return Collections.emptyMap(); } Type stringMapType = new TypeToken<Map<String, String>>() {}.getType(); return gson.fromJson(jsonString, stringMapType); } }
JsonUtil { public static Map<String, String> convertJsonStringToMap(String jsonString) { if (jsonString == null || jsonString.equals("") || jsonString.equals("{}")) { return Collections.emptyMap(); } Type stringMapType = new TypeToken<Map<String, String>>() {}.getType(); return gson.fromJson(jsonString, stringMapType); }  }
JsonUtil { public static Map<String, String> convertJsonStringToMap(String jsonString) { if (jsonString == null || jsonString.equals("") || jsonString.equals("{}")) { return Collections.emptyMap(); } Type stringMapType = new TypeToken<Map<String, String>>() {}.getType(); return gson.fromJson(jsonString, stringMapType); }  static Map<String, String> convertJsonStringToMap(String jsonString); }
JsonUtil { public static Map<String, String> convertJsonStringToMap(String jsonString) { if (jsonString == null || jsonString.equals("") || jsonString.equals("{}")) { return Collections.emptyMap(); } Type stringMapType = new TypeToken<Map<String, String>>() {}.getType(); return gson.fromJson(jsonString, stringMapType); }  static Map<String, String> convertJsonStringToMap(String jsonString);  }