@Test public void testConvert5_at_DateTimeFormat() throws Exception { LocalDate date1 = new LocalDate(2015, 4, 1); LocalDate localDate1 = new LocalDate(2015, 6, 10); LocalDate date2 = new LocalDate(2015, 5, 1); LocalDate localDate2 = new LocalDate(2015, 7, 10); Map<String, String> map = converter.convert(new DateForm5(date1 .toDate(), localDate1, new DateFormItem5(date2 .toDate(), localDate2))); assertThat(map.size(), is(4)); assertThat(map, hasEntry("date", "2015-04-01")); assertThat(map, hasEntry("localDate", "2015-06-10")); assertThat(map, hasEntry("item.date", "2015-05-01")); assertThat(map, hasEntry("item.localDate", "2015-07-10")); DateForm5 form = new DateForm5(); WebDataBinder binder = new WebDataBinder(form); binder.setConversionService(new DefaultFormattingConversionService()); binder.bind(new MutablePropertyValues(map)); assertThat(form.getDate(), is(date1.toDate())); assertThat(form.getLocalDate(), is(localDate1)); assertThat(form.getItem().getDate(), is(date2.toDate())); assertThat(form.getItem().getLocalDate(), is(localDate2)); }
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);  }