### Question:
MapAdapter extends XmlAdapter<Map, java.util.Map<String, java.lang.Object>> { @Override public Map marshal(java.util.Map<String, java.lang.Object> input) throws Exception { if (input == null) { return null; } else { Map output = new Map(); for (java.util.Map.Entry<String, java.lang.Object> entry : input.entrySet()) { String key = entry.getKey(); java.lang.Object value = entry.getValue(); if (value instanceof java.util.Map) { java.util.Map<String, java.lang.Object> nestedMap = new HashMap<>(); ((java.util.Map<?, ?>) value).forEach((k, v) -> nestedMap.put(k.toString(), v)); value = marshal(nestedMap); } output.getEntries().add(new MapEntry().withKey(key).withValue(value)); } return output; } }  @Override Map marshal(java.util.Map<String, java.lang.Object> input); @Override java.util.Map<String, java.lang.Object> unmarshal(Map input);  }### Answer:
@Test public void marshal() throws Exception { java.util.Map<String, java.lang.Object> input = new LinkedHashMap<>(); input.put("label", "News"); input.put("count", 7); java.util.Map<java.lang.Object, java.lang.Object> nestedMap = new LinkedHashMap<>(); nestedMap.put("test", 1); nestedMap.put(8, "test"); input.put("nested map", nestedMap); Map output = new MapAdapter().marshal(input); assertEquals(3, output.getEntries().size()); assertEquals("label", output.getEntries().get(0).getKey()); assertEquals("News", output.getEntries().get(0).getValue()); assertEquals("count", output.getEntries().get(1).getKey()); assertEquals(7, output.getEntries().get(1).getValue()); assertEquals("nested map", output.getEntries().get(2).getKey()); assertTrue(output.getEntries().get(2).getValue() instanceof Map); Map value = (Map) output.getEntries().get(2).getValue(); assertEquals(2, value.getEntries().size()); assertEquals("test", value.getEntries().get(0).getKey()); assertEquals(1, value.getEntries().get(0).getValue()); assertEquals("8", value.getEntries().get(1).getKey()); assertEquals("test", value.getEntries().get(1).getValue()); }
@Test public void marshalNull() throws Exception { assertNull(new MapAdapter().marshal(null)); }