When I get List from server with spring I get in client object user like this:
{
"id": 1,
"name": "hgfhj",
"age": 120,
"createdDate": 1457211138000,
"admin": true
}
UserController.java method:
@RequestMapping(value = "/user/", method = RequestMethod.GET)
public ResponseEntity<List<User>> getList() {
List usersList = userService.getList();
ResponseEntity<List<User>> respEntity = null;
if(usersList.isEmpty()){
respEntity =new ResponseEntity<List<User>>(HttpStatus.NO_CONTENT);
return respEntity;
}
respEntity =new ResponseEntity<List<User>>(usersList, HttpStatus.OK);
return respEntity;
}
And when I use Gson I get in client object user like this:
{
"id": 1,
"name": "hgfhj",
"age": 120,
"isAdmin": true,
"createdDate": "Mar 5, 2016 10:52:18 PM"
}
UserController.java method:
@RequestMapping(value = "/user/", method = RequestMethod.GET)
public String getList() {
List usersList = userService.getList();
ResponseEntity<List<User>> respEntity = null;
respEntity =new ResponseEntity<List<User>>(usersList, HttpStatus.OK);
Gson gson = new Gson();
String json = gson.toJson(usersList);
return json;
}
In all project user property name "isAdmin", I do not understand why it's changed to "admin". How can I use spring but get in client "isAdmin" without gson?
User.java:
@Entity
public class User {
/*@Column(name="id")*/
@Id
@GeneratedValue
private int id;
@Column(name="name")
private String name;
@Column(name="age")
private int age;
@Column(name="isAdmin")
private boolean isAdmin;
@Column(name="createdDate")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "dd.MM.yyyy")
private Date createdDate;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean isAdmin() {
return isAdmin;
}
public Date getCreatedDate() {
return createdDate;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}