title: Pass multiple parameters to rest API - Spring
body: <p>I am trying to figure out if it is possible to pass a JSON object to rest API, Or pass a multiple parameters to that API ? And how to read these parameters in Spring ? Lets assume that the url looks like the below examples : </p>
  
  <p>Ex.1 <code>http://localhost:8080/api/v1/mno/objectKey?id=1&amp;name=saif</code></p>
  
  <p>Is it valid to pass a JSON object like in the url below ?</p>
  
  <p>Ex.2 <code>http://localhost:8080/api/v1/mno/objectKey/{"id":1, "name":"Saif"}</code></p>
  
  <p>Questions:</p>
  
  <p>1) Is it possible to pass a JSON object to the url like in Ex.2?</p>
  
  <p>2) How can we pass and parse the parameters in Ex.1? </p>
  
  <p>I tried to write some methods to achieve my goal, but could not find the right solution?</p>
  
  <p>I tried to pass JSON object as @RequestParam</p>
  
  <p><code>http://localhost:8080/api/v1/mno/objectKey?id=1</code> There was an unexpected error <code>(type=Unsupported Media Type, status=415). Content type 'null' not supported</code></p>
  
  <p><code>http://localhost:8080/api/v1/mno/objectKey/id=1</code> There was an unexpected error <code>(type=Not Found, status=404). No message available</code></p>
  
  <p><code>http://localhost:8080/api/v1/mno/objectKey/%7B%22id%22:1%7D</code> There was an unexpected error <code>(type=Not Found, status=404). No message available</code></p>
  
  <pre><code>@RequestMapping(value="mno/{objectKey}",
                  method = RequestMethod.GET, 
                  consumes="application/json")
      public List&lt;Book&gt; getBook4(@RequestParam ObjectKey objectKey) {
          ...
      }
  </code></pre>
  
  <p>I tried to pass the JSON object as @PathVariable</p>
  
  <pre><code>@RequestMapping(value="ghi/{objectKey}",method = RequestMethod.GET)
      public List&lt;Book&gt; getBook2(@PathVariable ObjectKey objectKey) {
          ...         
      }
  </code></pre>
  
  <p>I created this object to hold the id parameter and other parameters like name , etc .... </p>
  
  <pre><code>class ObjectKey{
          long id;
          public long getId() {
              return id;
          }
          public void setId(long id) {
              this.id = id;
          }
      }
  </code></pre>