title: Spring Restcontroller not returning xml
body: <p>I'm getting json response from my controller even though I added the xml annotations to my model. I get the list of users in json with no problems. Can I use @Entity and @XmlRootElement in the same class?</p>
  
  <p>User.java</p>
  
  <pre><code>@Entity
  @Table(name = "usr")
  @XmlRootElement
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "ID", nullable = false, unique = true, length = 11)
      private int id;
  
      @Column(nullable = false)
      private String username;
  
      @Column(nullable = false)
      private String password;
  
      @Column(nullable = false)
      private String firstName;
  
      @Column(nullable = false)
      private String lastName;
  
      @Column(nullable = false)
      private String email;
  
      @OneToMany(mappedBy = "user")
      private List&lt;Post&gt; post;
  
      @OneToMany(mappedBy = "user")
      private List&lt;Friend&gt; friends;
  
      public List&lt;Friend&gt; getFriends() {
          return friends;
      }
  
      public void setFriends(List&lt;Friend&gt; friends) {
          this.friends = friends;
      }
  
      public List&lt;Post&gt; getPost() {
          return post;
      }
  
      public void setPost(List&lt;Post&gt; post) {
          this.post = post;
      }
  
      public int getId() {
          return id;
      }
  
  
      public void setId(int id) {
          this.id = id;
      }
  
      @XmlElement
      public String getUsername() {
          return username;
      }
  
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      @XmlElement
      public String getFirstName() {
          return firstName;
      }
  
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      @XmlElement
      public String getLastName() {
          return lastName;
      }
  
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      @XmlElement
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
  }
  </code></pre>
  
  <p>getAllUsers</p>
  
  <pre><code> @Override
      public List&lt;User&gt; getAllUsers() {
          List&lt;User&gt; users = new ArrayList&lt;User&gt;();
          Session session = HibernateUtil.getSessionAnnotationFactory().openSession();
          Transaction trns = null;
          try {
              trns = session.beginTransaction();
              users = session.createQuery("select firstName, lastName, email, username as name from User").list();
              trns.commit();
          } catch (RuntimeException e) {
              if (trns != null) {
                  trns.rollback();
              }
              e.printStackTrace();
          } finally {
              session.flush();
              session.close();
          }
          return users;
      }
  </code></pre>
  
  <p>and in the controller</p>
  
  <pre><code>@RequestMapping(value="/api/users", method = RequestMethod.GET)
  public List&lt;User&gt; getAllUsers() {
  
  //List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  UserDao userdao = new UserDaoImpl();
  List&lt;User&gt; users = userdao.getAllUsers();
  
  
  return users;
  
   }
  </code></pre>
  
  <p>What am I missing here?</p>