@Test public void testConvert6_Array() throws Exception { Map<String, String> map = converter.convert(new ArrayForm6(new int[] { 1, 2, 3 }, new double[] { 1.1, 1.2 }, new byte[] { 4, 5, 6 }, new String[] { "a", "b", "c" }, new ArrayFormItem6(new int[] { 11, 12, 13 }, new double[] { 11.1, 11.2 }, new byte[] { 14, 15, 16 }, new String[] { "d", "e", "f" }))); assertThat(map.size(), is(22)); assertThat(map, hasEntry("array1[0]", "1")); assertThat(map, hasEntry("array1[1]", "2")); assertThat(map, hasEntry("array1[2]", "3")); assertThat(map, hasEntry("array2[0]", "1.1")); assertThat(map, hasEntry("array2[1]", "1.2")); assertThat(map, hasEntry("array3[0]", "4")); assertThat(map, hasEntry("array3[1]", "5")); assertThat(map, hasEntry("array3[2]", "6")); assertThat(map, hasEntry("array4[0]", "a")); assertThat(map, hasEntry("array4[1]", "b")); assertThat(map, hasEntry("array4[2]", "c")); assertThat(map, hasEntry("item.array1[0]", "11")); assertThat(map, hasEntry("item.array1[1]", "12")); assertThat(map, hasEntry("item.array1[2]", "13")); assertThat(map, hasEntry("item.array2[0]", "11.1")); assertThat(map, hasEntry("item.array2[1]", "11.2")); assertThat(map, hasEntry("item.array3[0]", "14")); assertThat(map, hasEntry("item.array3[1]", "15")); assertThat(map, hasEntry("item.array3[2]", "16")); assertThat(map, hasEntry("item.array4[0]", "d")); assertThat(map, hasEntry("item.array4[1]", "e")); assertThat(map, hasEntry("item.array4[2]", "f")); ArrayForm6 form = new ArrayForm6(); WebDataBinder binder = new WebDataBinder(form); binder.setConversionService(new DefaultFormattingConversionService()); binder.bind(new MutablePropertyValues(map)); assertThat(form.getArray1().length, is(3)); assertThat(form.getArray1()[0], is(1)); assertThat(form.getArray1()[1], is(2)); assertThat(form.getArray1()[2], is(3)); assertThat(form.getArray2().length, is(2)); assertThat(form.getArray2()[0], is(1.1)); assertThat(form.getArray2()[1], is(1.2)); assertThat(form.getArray3().length, is(3)); assertThat(form.getArray3()[0], is((byte) 4)); assertThat(form.getArray3()[1], is((byte) 5)); assertThat(form.getArray3()[2], is((byte) 6)); assertThat(form.getArray4().length, is(3)); assertThat(form.getArray4()[0], is("a")); assertThat(form.getArray4()[1], is("b")); assertThat(form.getArray4()[2], is("c")); assertThat(form.getItem(), is(notNullValue())); assertThat(form.getItem().getArray1().length, is(3)); assertThat(form.getItem().getArray1()[0], is(11)); assertThat(form.getItem().getArray1()[1], is(12)); assertThat(form.getItem().getArray1()[2], is(13)); assertThat(form.getItem().getArray2().length, is(2)); assertThat(form.getItem().getArray2()[0], is(11.1)); assertThat(form.getItem().getArray2()[1], is(11.2)); assertThat(form.getItem().getArray3().length, is(3)); assertThat(form.getItem().getArray3()[0], is((byte) 14)); assertThat(form.getItem().getArray3()[1], is((byte) 15)); assertThat(form.getItem().getArray3()[2], is((byte) 16)); assertThat(form.getItem().getArray4().length, is(3)); assertThat(form.getItem().getArray4()[0], is("d")); assertThat(form.getItem().getArray4()[1], is("e")); assertThat(form.getItem().getArray4()[2], is("f")); }
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);  }