BeanToMapConvertor implements Cloneable { public Map<String, Object> toFlatMap(final Object obj){ final Map<String, Object> params = new HashMap<>(); toFlatMap(params, obj); return params; }  void setPropertyAccesor(String propertyAccesor); @Override BeanToMapConvertor clone(); void setPrefix(String prefix); void setPropertyAcceptor(PropertyAcceptor propertyAcceptor); void setValueConvertor(BiFunction<PropertyDescriptor, Object, Object> valueConvertor); void setFlatableObject(Function<Object, Boolean> flatableObject); void setPropertyNameConvertor(PropertyNameConvertor propertyNameConvertor); void setListOpener(String listOpener); void setListCloser(String listCloser); @SuppressWarnings("unchecked") Map<String, Object> toMap(final Object obj); Map<String, Object> toFlatMap(final Object obj); boolean isMappableValue(Object value); void toFlatMap(final Map<String, Object> params, final Object obj); void flatObject(final String prefixName, final Object obj, ValuePutter valuePutter); final static Function<Object, Boolean> DEFAULT_FLATABLE; }
@Test public void testWithDefaultIgnoreNull(){ UserEntity user = new UserEntity(); user.setId(11L); user.setUserName("testUserName"); RoleEntity role = new RoleEntity(); role.setId(20L); role.setName("testRoleName"); RoleEntity role1 = new RoleEntity(); role1.setId(21L); role1.setName("testRoleName1"); user.setRoles(Arrays.asList(role, role1)); MultiValueMap<String, Object> mmap = new MultiValueMap(); BEAN_TO_MAP_CONVERTOR.toFlatMap(mmap, user); String paramString = ParamUtils.comparableKeyMapToParamString(mmap); System.out.println("paramString:"+paramString); Assert.assertEquals("age=0&height=0.0&id=11&roles[0].id=20&roles[0].name=testRoleName&roles[0].version=0&roles[1].id=21&roles[1].name=testRoleName1&roles[1].version=0&userName=testUserName", paramString); user.setRole(role1); user.setRoles(null); Map<String, Object> map = beanToMapConvertor.toFlatMap(user); paramString = ParamUtils.comparableKeyMapToParamString(map); System.out.println("paramString:"+paramString); Assert.assertEquals("age=0&height=0.0&id=11&role.id=21&role.name=testRoleName1&role.version=0&userName=testUserName", paramString); }