title: Spring Android - POST Request - URL Encoded Params from Class Object
body: <p>I am trying to <strong>send some key-value pairs in Android Spring POST Request</strong>.It works correctly , if I am using a </p>
  
  <p><code>MultiValueMap&lt;String, String&gt; map= new LinkedMultiValueMap&lt;String, String&gt;();</code></p>
  
  <p>for that. <strong>Is there any way to avoid MultiValueMap &amp; directly send the Class Object as Request</strong>.</p>
  
  <p>One solution found is using Reflection , like the following </p>
  
  <pre><code>for (Field field:objAuth.getClass().getDeclaredFields()){
                      field.setAccessible(true);
                      map.add(field.getName(),field.get(objAuth)+"");
                  }
  </code></pre>
  
  <hr>
  
  <p>Code Snippet</p>
  
  <pre><code>        RestTemplate restTemplate = new RestTemplate(true);
          restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
          restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
          restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
  
  
          HttpHeaders requestHeaders = new HttpHeaders();
          requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
  
          MultiValueMap&lt;String, String&gt; map= new LinkedMultiValueMap&lt;String, String&gt;();
          Authenticate objAuth = new Authenticate();
          objAuth.setUserId("1");
          objAuth.setType("Type");
          objAuth.setoAuthToken("00112233");
          objAuth.setResponseCode("9689");
          objAuth.setResponseMessage("Last Message");
  
          /**
           * Using Reflection
           */
          for (Field field:objAuth.getClass().getDeclaredFields()){
              field.setAccessible(true);
              map.add(field.getName(),field.get(objAuth)+"");
          }
  
          HttpEntity&lt;?&gt; requestEntity = new HttpEntity&lt;Object&gt;(map , requestHeaders);
  
          String response = restTemplate.postForObject("http://posttestserver.com/post.php",requestEntity, String.class);
  </code></pre>