TypeConversion { 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 com.google.protobuf.Timestamp convertTimestamp(Date ts); static List<String> convertTagStringToList(String tags); static Map<String, String> convertJsonStringToMap(String jsonString); static Map<String, Enum> convertJsonStringToEnumMap(String jsonString); static String convertMapToJsonString(Map<String, String> map); static String convertEnumMapToJsonString(Map<String, Enum> map);  }
@Test public void convertJsonStringToMapShouldConvertJsonStringToMap() { String input = "{\"key\": \"value\"}"; Map<String, String> expected = new HashMap<>(); expected.put("key", "value"); assertThat(TypeConversion.convertJsonStringToMap(input), equalTo(expected)); }
@Test public void convertJsonStringToMapShouldReturnEmptyMapForEmptyJson() { String input = "{}"; Map<String, String> expected = Collections.emptyMap(); assertThat(TypeConversion.convertJsonStringToMap(input), equalTo(expected)); }