Spring Rest returning Json with @id -


see me classes: user.class

    package br.com.well.modelo;  import java.io.serializable;  import javax.persistence.entity; import javax.persistence.fetchtype; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.table;  import org.hibernate.annotations.cascade; import org.hibernate.annotations.cascadetype; import org.hibernate.annotations.fetch; import org.hibernate.annotations.fetchmode;  import com.fasterxml.jackson.annotation.jsonidentityinfo; import com.fasterxml.jackson.annotation.jsonignoreproperties; import com.fasterxml.jackson.annotation.objectidgenerators;  @entity //@jsonidentityinfo(generator=objectidgenerators.intsequencegenerator.class, property="@id") @jsonidentityinfo(generator=objectidgenerators.intsequencegenerator.class) @jsonignoreproperties(ignoreunknown = false) @table(name = "users") public class user implements serializable {     /**      *       */     private static final long serialversionuid = 1l;     @id     @generatedvalue(strategy = generationtype.identity)     private integer iduser;     private string username;     private string password;     private boolean expired;     private boolean locked;     private boolean enabled;     private string login;     @manytoone(fetch = fetchtype.eager)     @joincolumn(name = "idrole", insertable = true, updatable = true)     @fetch(fetchmode.join)     @cascade(cascadetype.save_update)     private role role;      public user() {         super();     }        public user(integer iduser, string username, string password, boolean expired, boolean locked, boolean enabled,             string login, role role) {         super();         this.iduser = iduser;         this.username = username;         this.password = password;         this.expired = expired;         this.locked = locked;         this.enabled = enabled;         this.login = login;         this.role = role;     }        public user(string username, string password, boolean expired, boolean locked, boolean enabled, string login,             role role) {         super();         this.username = username;         this.password = password;         this.expired = expired;         this.locked = locked;         this.enabled = enabled;         this.login = login;         this.role = role;     }      public integer getiduser() {         return iduser;     }      public void setiduser(integer iduser) {         this.iduser = iduser;     }      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;     }      public boolean isexpired() {         return expired;     }      public void setexpired(boolean expired) {         this.expired = expired;     }      public boolean islocked() {         return locked;     }      public void setlocked(boolean locked) {         this.locked = locked;     }      public boolean isenabled() {         return enabled;     }      public void setenabled(boolean enabled) {         this.enabled = enabled;     }      public role getrole() {         return role;     }      public void setrole(role role) {         this.role = role;     }      public string getlogin() {         return login;     }      public void setlogin(string login) {         this.login = login;     }      @override     public int hashcode() {         final int prime = 31;         int result = 1;         result = prime * result + ((iduser == null) ? 0 : iduser.hashcode());         return result;     }      @override     public boolean equals(object obj) {         if (this == obj)             return true;         if (obj == null)             return false;         if (getclass() != obj.getclass())             return false;         user other = (user) obj;         if (iduser == null) {             if (other.iduser != null)                 return false;         } else if (!iduser.equals(other.iduser))             return false;         return true;     }   }  role.class       package br.com.well.modelo;  import java.io.serializable; import java.util.list;  import javax.persistence.cascadetype; import javax.persistence.entity; import javax.persistence.fetchtype; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.onetomany; import javax.persistence.table;  import com.fasterxml.jackson.annotation.jsonidentityinfo; import com.fasterxml.jackson.annotation.jsonignore; import com.fasterxml.jackson.annotation.jsonignoreproperties; import com.fasterxml.jackson.annotation.objectidgenerators;  @entity //@jsonidentityinfo(generator=objectidgenerators.intsequencegenerator.class, property="@id") @jsonidentityinfo(generator=objectidgenerators.intsequencegenerator.class) @table(name = "roles")  public class role implements serializable {      /**      *       */     private static final long serialversionuid = 1l;     @id     @generatedvalue(strategy = generationtype.identity)     private integer idrole;     private string role;     @jsonignore     @onetomany(mappedby = "role", fetch = fetchtype.eager, cascade = cascadetype.all)     private list<user> users;      public role() {         super();     }        public role(integer idrole, string role, list<user> users) {         super();         this.idrole = idrole;         this.role = role;         this.users = users;     }        public role(string role, list<user> users) {         super();         this.role = role;         this.users = users;     }      public integer getidrole() {         return idrole;     }      public void setidrole(integer idrole) {         this.idrole = idrole;     }      public string getrole() {         return role;     }      public void setrole(string role) {         this.role = role;     }      public list<user> getusers() {         return users;     }      public void setusers(list<user> users) {         this.users = users;     }      @override     public int hashcode() {         final int prime = 31;         int result = 1;         result = prime * result + ((idrole == null) ? 0 : idrole.hashcode());         return result;     }      @override     public boolean equals(object obj) {         if (this == obj)             return true;         if (obj == null)             return false;         if (getclass() != obj.getclass())             return false;         role other = (role) obj;         if (idrole == null) {             if (other.idrole != null)                 return false;         } else if (!idrole.equals(other.idrole))             return false;         return true;     }  } 

controller

  @requestmapping(value = "/getusers", method = requestmethod.get)     public responseentity<list<user>> getusers() {         userdao dao = new userdao();         list<user> users = dao.getusers();         (user emp : users)             system.out.println(emp.getusername());         if (users.isempty())             return new responseentity<list<user>>(httpstatus.no_content);         return new responseentity<list<user>>(users, httpstatus.ok);     } 

json returned:

[ { "@id": 1, "iduser": 1, "username": "well", "password": "12345", "expired": true, "locked": true, "enabled": true, "login": "well", "role": { "@id": 2, "idrole": 1, "role": "role_user" } }, { "@id": 3, "iduser": 2, "username": "bárbara", "password": "12345", "expired": true, "locked": true, "enabled": true, "login": "barbara", "role": { "@id": 4, "idrole": 2, "role": "role_admin" } } ]

why @id in json return?

i can't convert json object

how can solve this? what's wrong?

thanks


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -