### Question:
JsonUtils { public static String mapToString(Map<String, String> map) { if (map == null || map.isEmpty()) { return "{}"; } try { StringWriter out = new StringWriter(); AwsJsonWriter writer = getJsonWriter(out); writer.beginObject(); for (Map.Entry<String, String> entry : map.entrySet()) { writer.name(entry.getKey()).value(entry.getValue()); } writer.endObject(); writer.close(); return out.toString(); } catch (IOException e) { throw new AmazonClientException("Unable to serialize to JSON String.", e); } }  @Deprecated static void setJsonEngine(JsonEngine jsonEngine); static AwsJsonReader getJsonReader(Reader in); static AwsJsonWriter getJsonWriter(Writer out); @SuppressWarnings("unchecked") static Map<String, String> jsonToMap(Reader in); @SuppressWarnings("unchecked") static Map<String, String> jsonToMap(String json); @SuppressWarnings("unchecked") static Map<String, String> jsonToStringMapWithList(Reader in); static String mapToString(Map<String, String> map);  }### Answer:
@Test public void testEmptyMapToJson() { Map<String, String> source = new HashMap<String, String>(); assertEquals("empty map", "{}", JsonUtils.mapToString(source)); }
@Test public void testWritePerformance() throws IOException { Map<String, String> map = new HashMap<String, String>(); for (int i = 0; i < 5000; i++) { map.put("key" + i, "value" + i); } System.out.println("Deserialize a JSON string with a 5000 properties map 1000 times"); long start = System.nanoTime(); for (int i = 0; i < 1000; i++) { JsonUtils.mapToString(map); } System.out.println("Write elapsed: " + (System.nanoTime() - start) / 1000000 + "ms"); }