Json Spring@RequestMapping未解析int-ID

Json Spring@RequestMapping未解析int-ID,json,spring,rest,jackson,Json,Spring,Rest,Jackson,我尝试使用Spring4在restful服务中返回一个用户对象,使用SpringBootTomcat而不使用MVC,但它没有将整个对象解析为JSON。My User.java: @Entity public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; private String username

我尝试使用Spring4在restful服务中返回一个用户对象,使用SpringBootTomcat而不使用MVC,但它没有将整个对象解析为JSON。My User.java:

@Entity
public class User implements Serializable
{
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
private int id;
private String username;
private String password;

// getters and setters
}
我的服务:

@ResponseBody
@RequestMapping(value="/service/user/save", method=RequestMethod.PUT, produces="application/json;charset=ISO-8859-1", consumes="application/json;charset=ISO-8859-1")
public User addUser(@RequestBody User user) throws AppException
{
    return facade.save(user); // returns a User with it's ID
}
我的JSON结果没有ID:

{
username: "john",
password: "1234",
}
仅对用户名和密码进行解析。 但是,当我返回手动解析的字符串时,如:

@ResponseBody
@RequestMapping(value="/service/user/save", method=RequestMethod.PUT, produces="application/json;charset=ISO-8859-1", consumes="application/json;charset=ISO-8859-1")
public User addUser(@RequestBody User user) throws AppException
{
    user = facade.save(user);
    return new ObjectMapper().writeValueAsString(user);
}
它工作正常,返回:

{
id: 23,
username: "john",
password: "1234",
}

我缺少什么?

facade和cs有什么区别?返回facade.saveuser;user=cs.saveuser;它们是不同的类吗?没有区别-这是我在这篇文章上固定的同一个对象。