title: Omit ModelAttribute from view
body: <p>I have a rest application that returns json/xml.  I use jackson and jaxb for conversion.  Some methods need to accept a query_string.  I've used @ModelAttribute to map the query_string into an object, but this forces the object into my view.  I do not want the object to appear in the view.</p>
  
  <p>I think I need to use something other than @ModelAttribute, but I can't figure out how to do the binding, but not modify the view.  If I omit @ModelAttribute annotation, the object appears in the view as the variable name (eg: "sourceBundleRequest").</p>
  
  <p>Example Url:</p>
  
  <pre><code>http://localhost:8080/rest/sourcebundles/?updateDate=20100501&amp;label=urgent
  </code></pre>
  
  <p>Controller Method:</p>
  
  <pre><code>@RequestMapping(value = {"", "/"}, method = RequestMethod.GET)
  public String getAll(@ModelAttribute("form") SourceBundleRequest sourceBundleRequest, BindingResult result, ModelMap model) throws ApiException {
      // Detect and report errors.
      if (result.hasErrors()) {
         // (omitted for clarity)
      }
  
      // Fetch matching data.
      PaginatedResponse&lt;SourceBundle&gt; sourceBundleResponse = null;
      try {
          int clientId = getRequestClientId();
          sourceBundleResponse = sourceBundleService.get(clientId, sourceBundleRequest);
      } catch (ApiServiceException e) {
          throw new ApiException(ApiErrorType.INTERNAL_ERROR, "sourceBundle fetch failed");
      }
  
      // Return the response.
      RestResponse&lt;PaginatedResponse&gt; restResponse = new RestResponse&lt;PaginatedResponse&gt;(200, "OK");
      restResponse.setData(sourceBundleResponse);
      model.addAttribute("resp", restResponse);
      // XXX - how do I prevent "form" from appearing in the view?
      return "restResponse";
  }
  </code></pre>
  
  <p>Example Output:</p>
  
  <pre><code>"form": {
      "label": "urgent",
      "updateDate": 1272697200000,
      "sort": null,
      "results": 5,
      "skip": 0
  },
  "resp": {
      "code": 200,
      "status": "OK",
      "data": {
          "totalAvailable": 0,
          "resultList": [ ]
      }
  }
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>"resp": {
      "code": 200,
      "status": "OK",
      "data": {
          "totalAvailable": 0,
          "resultList": [ ]
      }
  }
  </code></pre>
  
  <p><strong>Omitting @ModelAttribute("form")</strong></p>
  
  <p>If I simply omit @ModelAttribute("form"), I still get the undesirable response but the incoming form is named by the object name.  The response looks like this:</p>
  
  <pre><code>"resp": {
      "code": 200,
      "status": "OK",
      "data": {
          "totalAvailable": 0,
          "resultList": [ ]
      }
  },
  "sourceBundleRequest": {
      "label": "urgent",
      "updateDate": 1272697200000,
      "sort": null,
      "results": 5,
      "skip": 0
  }
  </code></pre>