Note that there are some explanatory texts on larger screens.

plurals
  1. POChild object is null during Jackson serialization?
    text
    copied!<p>I captured the json response and I see that it is {"page":"1","total":"2","records":"15","rows":[{"id":1,"firstName":"John","lastName":"Smith","username":"john","password":"21232f297a57a5a743894a0e4a801fc3","role":null},{"id":2,"firstName":"Jane","lastName":"Adams","username":"jane","password":"ee11cbb19052e40b07aac0ca060c23ee","role":null},</p> <p>My User and Role classes are super simple, so I think I must be overlooking something trivial.</p> <pre><code>@Entity(name="user") public class User implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String firstName; private String lastName; @Column(unique=true) private String username; private String password; @JsonIgnore @OneToMany(mappedBy="user", cascade={CascadeType.PERSIST, CascadeType.MERGE},fetch =FetchType.EAGER) private List&lt;Role&gt; roles = new ArrayList&lt;Role&gt;(); public List&lt;Role&gt; getRoles() { return roles; } public void setRoles(List&lt;Role&gt; roles) { this.roles = roles; } @ManyToOne private Role role; public User() {} public User(String username, String password, String firstName, String lastName, Role role) { this.username = username; this.password = password; this.firstName = firstName; this.lastName = lastName; this.role = role; } public User(String username, String firstName, String lastName, Role role) { this.username = username; this.firstName = firstName; this.lastName = lastName; this.role = role; } public User(String username) { this.username = username; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } 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 Role getRole() { return role; } public void setRole(Role role) { this.role = role; } } @Entity(name="role") public class Role implements Serializable{ /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @JsonIgnore @ManyToOne @JoinColumn (name = "user_id", nullable= true) private User user; private Integer role; public Role() {} public Role(Integer role) { this.role = role; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Integer getRole() { return role; } public void setRole(Integer role) { this.role = role; } } </code></pre> <p>I tried also </p> <blockquote> <p>@JsonUnwrapped @ManyToOne private Role role;</p> </blockquote> <p>but that's even worse because in this case my json doesn't have the role at all. {"id":1,"firstName":"John","lastName":"Smith","username":"john","password":"21232f297a57a5a743894a0e4a801fc3"},</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload