@Test public void testConvert2_ListOfJavaBean() throws Exception { Map<String, String> map = converter.convert( new BatchUpdateUserForm2(Arrays.asList( new UpdateUserCriteriaForm2("yamada", 20), new UpdateUserCriteriaForm2("tanaka", 50)), LogicalOperator2.AND)); assertThat(map.size(), is(5)); assertThat(map, hasEntry("criteria[0].name", "yamada")); assertThat(map, hasEntry("criteria[0].age", "20")); assertThat(map, hasEntry("criteria[1].name", "tanaka")); assertThat(map, hasEntry("criteria[1].age", "50")); assertThat(map, hasEntry("operator", "AND")); BatchUpdateUserForm2 form = new BatchUpdateUserForm2(); WebDataBinder binder = new WebDataBinder(form); binder.bind(new MutablePropertyValues(map)); assertThat(form.getCriteria(), is(notNullValue())); assertThat(form.getCriteria().size(), is(2)); assertThat(form.getCriteria().get(0).getName(), is("yamada")); assertThat(form.getCriteria().get(0).getAge(), is(20)); assertThat(form.getCriteria().get(1).getName(), is("tanaka")); assertThat(form.getCriteria().get(1).getAge(), is(50)); assertThat(form.getOperator(), is(LogicalOperator2.AND)); }
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);  }