title: Passing JSON objects in a REST HTTP GET request using Spring MVC
body: <p>According to this <a href="http://martinfowler.com/articles/richardsonMaturityModel.html#level2" rel="noreferrer">REST model</a> and to what I think is a consensus on REST: every REST <strong>retrieval</strong> should be performed as a HTTP GET request. 
  <strong>The problem now is how to treat complex JSON objects as parameters in GET requests with Spring MVC.</strong>
  There is also another consensus I found saying "use POST for retrievals!" just because "the big companies do this!", but <strong>I have been asked to try to stick to the "REST level 2 rules".</strong></p>
  
  <p>First question: am I trying to do something that make sense?</p>
  
  <p><strong>I want to send via GET requests arrays / lists / sets of JSON objects, in Java with Spring MVC.</strong>
  I can not figure out what's wrong with my attempts, I have tried to add/remove double quotes, played around with the URL parameters, but I can not achieve this goal.</p>
  
  <p>What's wrong with the following code? The code snippet is coming from a MVC controller.</p>
  
  <pre><code>@RequestMapping(
          value = "/parseJsonDataStructures",
          params = {
                  "language",
                  "jsonBeanObject"
  
          }, method = RequestMethod.GET, headers = HttpHeaders.ACCEPT + "=" + MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public HttpEntity&lt;ParsedRequestOutputObject&gt; parseJsonDataStructures(
  
          @RequestParam String language,
          @RequestParam CustomJsonBeanObject[] customJsonBeanObjects){
  
      try {
          ParsedRequestOutputObject responseFullData = customJsonBeanObjectService.parseJsonDataStructures(customJsonBeanObjects, language);
  
          return new ResponseEntity&lt;&gt;(responseFullData, HttpStatus.OK);
      } catch (Exception e) {
          // TODO
      }
  }
  </code></pre>
  
  <p>I've tried multiple ways to build the URL request (always getting HTTP code 400 Bad Request), this is an example:</p>
  
  <pre><code>http://[...]/parseJsonDataStructures?language=en&amp;jsonBeanObject={"doubleObject":10, "enumObject":"enumContent", "stringObject":"stringContent"}
  </code></pre>
  
  <p>The JSON object variables ar of type:</p>
  
  <ul>
  <li>Double (not the primitive)</li>
  <li>enum</li>
  <li>String</li>
  </ul>
  
  <p>I am assuming I can pass multiple <code>jsonBeanObject</code> parameters one after the other.</p>
  
  <p>The <code>jsonBeanObject</code> Java bean is:</p>
  
  <pre><code>public class CustomJsonBeanObject {
  
      private Double doubleObject;
      private CustomEnum enumObject;
      private String stringObject;
  
      /**
       * Factory method with validated input.
       *
       * @param doubleObject
       * @param enumObject
       * @param stringObject
       * @return
       */
      public static CustomJsonBeanObject getNewValidatedInstance(Double doubleObject, CustomEnum enumObject, String stringObject) {
          return new CustomJsonBeanObject
                  (
                          doubleObject ,
                          enumObject   ,
                          stringObject
                  );
      }
  
      private CustomJsonBeanObject(Double doubleObject, CustomEnum enumObject, String stringObject) {
          this.doubleObject = doubleObject;
          this.enumObject = enumObject;
          this.stringObject = stringObject;
      }
  
  
      public CustomJsonBeanObject() {}
  
      // getter setter stuff
  
      @Override
      public String toString() {
          return ToStringBuilder.reflectionToString(this);
      }
  }
  </code></pre>