title: @Restcontroller method with multiple custom objects
body: <p>I have a Spring RestController as,</p>
  
  <pre><code>@RestController
  public class TestController {
  
      @RequestMapping("/checkTestObject")
      public MyPOJOObject3 checkTestObject(MyPOJOObject1 obj1, MyPOJOObject2 obj2) {
          //Using obj1 and obj2 - business logic
          return new MyPOJOObject3();
      }
  }
  </code></pre>
  
  <p>Where MyPOJOObject1, MyPOJOObject2 and MyPOJOObject3 are 3 custom objects defined by me with setter and getter fields. And client I have tried as,</p>
  
  <pre><code>public class TestClient(
      public static void main(String args[]){
  
          MyPOJOObject1 obj1 = new MyPOJOObject1();
          obj1.setInfoChgDate(new Date());
          obj1.setInfoRegUserName("NEW_USER");
          MyPOJOObject2 obj2 = new MyPOJOObject2();
          obj2.setId(121l);
          obj2.setDescription("Hello TestDemo");
  
          String url = "http://localhost:8080/TestApp/checkTestObject";
          MultiValueMap&lt;String, Object&gt; formData = new LinkedMultiValueMap&lt;String, Object&gt;();
          formData.set("obj1", obj1);
          formData.set("obj2", obj2);
          // Prepare acceptable media type
          List&lt;MediaType&gt; acceptableMediaTypes = new ArrayList&lt;MediaType&gt;();
          acceptableMediaTypes.add(MediaType.ALL);
          HttpHeaders headers = new HttpHeaders();
          headers.setAccept(acceptableMediaTypes);
          HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; httpEntity = new HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt;(formData, headers);
          ResponseEntity&lt;MyPOJOObject3&gt; response = null;
          try {
              response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, MyPOJOObject3.class);
              logger.debug(url + " :: response :: " + response.toString());
          } catch (Exception exception) {
              logger.error(url + " :: Exception thrown :: ", exception);
          }
          //response.getBody();
      }
  )
  </code></pre>
  
  <p>When I deploy the RestController on tomcat and run the client I get error as,</p>
  
  <pre><code>2015-07-27 14:54:47,230 [main] ERROR TestController - http://localhost:8080/TestApp/checkTestObject :: Exception thrown :: 
  org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
      at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521)
  </code></pre>
  
  <p>My question is, Is this the right way to send and recieve custom objects over REST with Spring or is there any other way? I tried using other RestTemplate methods like getForObject, postForObject, postForLocation etc. but to no luck. Please let me know if there is any standard way of sending recieving complex objects over REST via JSON or I have to go in a way like - convert object to JSON string - send over - convert back JSON String to Object and vice versa. Please let me know the options as I am struck with my work here</p>
  
  <p>Thanks</p>