title: Return JSON data type/view from Spring controller
body: <p>How do I convert an existing XML-based web service to JSON-type web service? </p>
  
  <p>I have this sample resource:</p>
  
  <pre><code>@Controller
  public class CustomerController {
      @RequestMapping(value="customers", method=RequestMethod.GET)
      public @ResponseBody CustomerList customers(Model model) {
          CustomerList list = new CustomerList();
          list.getCustomer().add(new Customer("1", "John Doe"));
          list.getCustomer().add(new Customer("2", "Jane Doe"));
          return list;
      }
  }
  </code></pre>
  
  <p>So far, I am not experiencing any error with regards to accessing it, I just want to change the data that this service return to the client from XML to JSON.</p>
  
  <p>With this entity:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "", propOrder = {
      "customer"
  })
  @XmlRootElement(name = "CustomerList")
  public class CustomerList {
  
      @XmlElement(name = "Customer", required = true)
      protected List&lt;Customer&gt; customer;
  
      public List&lt;Customer&gt; getCustomer() {
          if (customer == null) {
              customer = new ArrayList&lt;Customer&gt;();
          }
          return this.customer;
      }
  
  }
  </code></pre>
  
  <p>servlet-context.xml:    </p>
  
  <pre><code>&lt;oxm:jaxb2-marshaller id="marshaller" contextPath="com.mycompany.api.model"/&gt;
  &lt;beans:bean id="customerList" class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;
          &lt;beans:constructor-arg ref="marshaller"/&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p>How can I change the output of the service to JSON? Do I need to put JSON-type annotations in the entity/model? </p>