Announcement Announcement Module
Collapse
No announcement yet.
Converter not called? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converter not called?

    Hi,

    I have a problem that I can't figure out. I have a flow that is suppose to register a new user with but for some reason the authorities doesn't get the correct type.

    The user:
    Code:
    public class CustomUser implements Serializable, UserDetails {
    ..
        private List<Role> roles = new ArrayList<Role>();
    
        public Role[] getAuthorities() {
            return roles.toArray(new Role[0]);
        }
    
        public List<Role> getRoles() {
            return roles;
        }
    
        public void setRoles(List<Role> roles) {
            this.roles = roles;
        }
    The Role:
    Code:
    public class Role implements GrantedAuthority, Serializable {
    
        private String authority;
    
        public String getAuthority() {
            return authority;
        }
    
        public void setAuthority(String authority) {
            this.authority = authority;
        }
    
        public int compareTo(Object o) {
            return 0;
        }
    
        public String toString() {
            return authority;
        }
    The converter:
    Code:
    public class StringToRole extends StringToObject implements Serializable {
    
        private RoleService service;
    
        public RoleService getService() {
            return service;
        }
    
        public void setService(RoleService service) {
            this.service = service;
        }
    
        protected Object toObject(String string, Class targetClass) throws Exception {
            return service.getRole(string);
        }
    
        protected String toString(Object object) throws Exception {
            Role role = (Role) object;
            return role.toString();
        }
    
        public StringToRole() {
            super(Role.class);
        }
    }
    This works fine when reading the user and roles in the flow but when I try to save it to the database somehow the CustomUser.getRoles returns an ArrayList of Strings.

    Anyone know why that is?

    Best regards
    JohanS

  • #2
    maybe this one helps...

    Is this what you meant?-> http://java.sun.com/j2se/1.4.2/docs/...ializable.html
    http://www.business567.com

    Comment


    • #3
      I'm not sure what you mean?

      I believe my problem is that the method toObject isn't called when trying to go back to my domain model. But since I'm clueless to why it isn't I'm open to any suggestions on how to fix my problem.

      Comment

      Working...
      X