Commit f9b4ae49be11e6bcfbd5b335de81dfb9a3b2b1ea

Authored by jcartign
1 parent 896af76d

Fix recursion in rest response from UserRestController

src/main/java/fr/plil/sio/web/mvc/Role.java
1 1 package fr.plil.sio.web.mvc;
2 2  
  3 +import com.fasterxml.jackson.annotation.JsonBackReference;
3 4 import org.springframework.security.core.GrantedAuthority;
4 5  
5 6 import javax.persistence.*;
... ... @@ -19,6 +20,7 @@ public class Role implements GrantedAuthority {
19 20 private String name;
20 21  
21 22 @ManyToMany
  23 + @JsonBackReference
22 24 @JoinTable(
23 25 name = "USER_ROLE_T",
24 26 joinColumns = @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID"),
... ...
src/main/java/fr/plil/sio/web/mvc/User.java
1 1 package fr.plil.sio.web.mvc;
2 2  
3 3  
  4 +import com.fasterxml.jackson.annotation.JsonManagedReference;
4 5 import org.springframework.security.core.GrantedAuthority;
5 6 import org.springframework.security.core.userdetails.UserDetails;
6 7  
... ... @@ -25,6 +26,7 @@ public class User implements UserDetails {
25 26 private String password;
26 27  
27 28 @ManyToMany(mappedBy = "users", fetch = FetchType.EAGER)
  29 + @JsonManagedReference
28 30 private Set<Role> roles = new TreeSet<>();
29 31  
30 32 public Set<Role> getRoles() {
... ...
src/main/java/fr/plil/sio/web/mvc/UserRestController.java
1 1 package fr.plil.sio.web.mvc;
2 2  
  3 +import org.springframework.web.bind.annotation.PathVariable;
3 4 import org.springframework.web.bind.annotation.RequestMapping;
4 5 import org.springframework.web.bind.annotation.RequestMethod;
5 6 import org.springframework.web.bind.annotation.RestController;
... ... @@ -13,8 +14,13 @@ public class UserRestController {
13 14 @Resource
14 15 private UserService userService;
15 16  
16   - @RequestMapping(value = "/users/", method = RequestMethod.GET)
  17 + @RequestMapping(value = "/api/users/", method = RequestMethod.GET)
17 18 public List<User> listUsers() {
18 19 return userService.findAll();
19 20 }
  21 +
  22 + @RequestMapping(value = "/api/users/{username}/", method = RequestMethod.GET)
  23 + public User listUsers(@PathVariable String username) {
  24 + return userService.findByUsername(username);
  25 + }
20 26 }
21 27 \ No newline at end of file
... ...