RestUtils { @SuppressWarnings({ "rawtypes", "unchecked" }) public static String keysToParamString(Map params){ return ParamUtils.toParamString(params, (BiFunction<String, Object, String>)(k, v)->{ return k+"={"+k+"}"; }); } private  RestUtils(); static BeanToMapConvertor getBeanToMapConvertor(); static boolean isRequestBodySupportedMethod(HttpMethod method); static boolean isRequestBodySupportedMethod(RequestMethod method); static boolean isOkHttp3Present(); static HttpEntity<?> createFormEntity(final Object obj); static HttpEntity<?> createFormEntity(final Object obj, BeanToMapConvertor convertor); static MultiValueMap<String, Object> toMultiValueMap(final Object obj); static MultiValueMap<String, String> toMultiValueStringMap(final Object obj); @SuppressWarnings("unchecked") static MultiValueMap<String, V> toMultiValueMap(final Object obj, BeanToMapConvertor convertor); static String propertiesToParamString(Object request); @SuppressWarnings({ "rawtypes", "unchecked" }) static String keysToParamString(Map params); static HttpHeaders createHeader(MediaType mediaType); static HttpEntity<T> createHttpEntity(T obj, MediaType mediaType); static HttpEntity<T> createHttpEntity(T obj, HttpHeaders headers); static final String CLASS_OK_HTTP_CLIENT; static final String LIST_LEFT; static final String LIST_RIGHT; static final String DOT_ACCESOR; static final String ACCEPT_CHARSET; static final HttpHeaders FORM_HEADER; static final HttpHeaders XML_HEADER; static final HttpHeaders JSON_HEADER; static final HttpHeaders TEXT_HEADER; }
@Test public void testKeysToParamString(){ MultiValueMap<String, Object> params = new LinkedMultiValueMap<String, Object>(); params.add("param1", "value1"); params.add("param1", "value1-2"); params.set("param2", "value2"); params.set("param3", 3); String result = RestUtils.keysToParamString(params); System.out.println("result:"+result); assertThat(result).isEqualTo("param1={param1}&param1={param1}&param2={param2}&param3={param3}"); }
@Test public void testFlatable(){ 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> params = new LinkedMultiValueMap<String, Object>(); beanToMapConvertor.flatObject("", user, (k, v, ctx)->{ System.out.println("k:"+k+", ctx.getName():"+ctx.getName()); params.add(k, v); }); String result = RestUtils.keysToParamString(params); System.out.println("result: " + result); assertThat(result).isEqualTo("age={age}&height={height}&id={id}&roles[0].id={roles[0].id}&roles[0].name={roles[0].name}&roles[0].version={roles[0].version}&roles[1].id={roles[1].id}&roles[1].name={roles[1].name}&roles[1].version={roles[1].version}&userName={userName}"); }