Mult { public Map<String, Object> toMap() { Stack<Map<String, Object>> mapStack = new Stack<Map<String, Object>>(); mapStack.push(new HashMap<String, Object>()); for (String s = order("", 1); !s.equals(""); s = order(s, 1)) { String[] keys = s.split(","); for (int i = 0; i < keys.length; i++) { String key = keys[i]; if (key.startsWith("\"") && key.endsWith("\"")) key = key.substring(1, key.length() - 1); if (i == (keys.length - 1)) { mapStack.peek().put(key, get(s)); } else { Map<String, Object> map; if (mapStack.peek().containsKey(key)) { map = (Map) mapStack.peek().get(key); } else { map = new TreeMap<String, Object>(); mapStack.peek().put(key, map); } mapStack.push(map); } } for (int i = 0; i < keys.length - 1; i++) { mapStack.pop(); } } Map<String, Object> m = (Map<String, Object>) traverseAndConvertNestedMapsWithNumericKeysToLists(mapStack.pop(), true); return m; }  int getCount(); String order(String startSubscript, int direction); String get(String subscript); void put(String subscript, String value); void add(Map map); void add(List list); void add(JsonNode jsonNode); int position(String subscript); String subscript(int position); String getFirst(); String getLast(); Map<String, Object> toMap(); @JsonValue JsonNode toJsonNode(); @Override boolean equals(Object o); @Override int hashCode(); static Mult create(Map map); static Mult create(List list); static Mult create(JsonNode json);  }
@Test public void testToMap() { SortedMap<String, String> p = new TreeMap<String, String>(); p.put("fred", "wilma"); p.put("barney", "betty"); Mult mult = Mult.create(p); Map<String,Object> map = mult.toMap(); assertThat(map.size(), is(mult.getCount())); assertThat((String) map.get("fred"), is("wilma")); assertThat((String) map.get("barney"), is("betty")); }