@Test public void testConvert4_MapOfJavaBean() throws Exception { Map<String, String> source = new LinkedHashMap<String, String>(); source.put("aaa", "111"); source.put("bbb", "222"); source.put("ccc", "333"); Map<String, String> map = converter.convert(new SearchForm4(source)); assertThat(map.size(), is(3)); assertThat(map, hasEntry("etc[aaa]", "111")); assertThat(map, hasEntry("etc[bbb]", "222")); assertThat(map, hasEntry("etc[ccc]", "333")); SearchForm4 form = new SearchForm4(); WebDataBinder binder = new WebDataBinder(form); binder.bind(new MutablePropertyValues(map)); assertThat(form.getEtc(), is(notNullValue())); assertThat(form.getEtc().size(), is(3)); assertThat(form.getEtc(), hasEntry("aaa", "111")); assertThat(form.getEtc(), hasEntry("bbb", "222")); assertThat(form.getEtc(), hasEntry("ccc", "333")); }
private Map<String, String> convert(String prefix, Map<?, ?> value) { Map<String, String> map = new LinkedHashMap<String, String>(); for (Map.Entry<?, ?> e : value.entrySet()) { if (StringUtils.isEmpty(prefix)) { map.putAll(this.convert(e.getKey().toString(), e.getValue())); } else { map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e .getValue())); } } return map; }
ObjectToMapConverter { private Map<String, String> convert(String prefix, Map<?, ?> value) { Map<String, String> map = new LinkedHashMap<String, String>(); for (Map.Entry<?, ?> e : value.entrySet()) { if (StringUtils.isEmpty(prefix)) { map.putAll(this.convert(e.getKey().toString(), e.getValue())); } else { map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e .getValue())); } } return map; } }
ObjectToMapConverter { private Map<String, String> convert(String prefix, Map<?, ?> value) { Map<String, String> map = new LinkedHashMap<String, String>(); for (Map.Entry<?, ?> e : value.entrySet()) { if (StringUtils.isEmpty(prefix)) { map.putAll(this.convert(e.getKey().toString(), e.getValue())); } else { map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e .getValue())); } } return map; } ObjectToMapConverter(FormattingConversionService conversionService); }
ObjectToMapConverter { private Map<String, String> convert(String prefix, Map<?, ?> value) { Map<String, String> map = new LinkedHashMap<String, String>(); for (Map.Entry<?, ?> e : value.entrySet()) { if (StringUtils.isEmpty(prefix)) { map.putAll(this.convert(e.getKey().toString(), e.getValue())); } else { map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e .getValue())); } } return map; } ObjectToMapConverter(FormattingConversionService conversionService); Map<String, String> convert(Object object); Map<String, String> convert(String prefix, Object object); }
ObjectToMapConverter { private Map<String, String> convert(String prefix, Map<?, ?> value) { Map<String, String> map = new LinkedHashMap<String, String>(); for (Map.Entry<?, ?> e : value.entrySet()) { if (StringUtils.isEmpty(prefix)) { map.putAll(this.convert(e.getKey().toString(), e.getValue())); } else { map.putAll(this.convert(prefix + "[" + e.getKey() + "]", e .getValue())); } } return map; } ObjectToMapConverter(FormattingConversionService conversionService); Map<String, String> convert(Object object); Map<String, String> convert(String prefix, Object object);  }