Skip to content

Commit

Permalink
Fix recursive object serializing and lazy fields access
Browse files Browse the repository at this point in the history
  • Loading branch information
massijay committed Jul 14, 2022
1 parent 13e4842 commit 5a66d00
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mcris.triprecorder.models.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;

import java.sql.Timestamp;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class Geopoint {
private String label;
@ManyToOne
@JoinColumn(name = "trip_id", referencedColumnName = "id", nullable = false)
@JsonIgnore
private Trip trip;

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mcris.triprecorder.models.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;

import java.sql.Timestamp;
Expand Down Expand Up @@ -29,6 +30,7 @@ public class Trip {
private String notes;
@OneToMany(mappedBy = "trip")
private Collection<Geopoint> geopoints;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
private User user;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.mcris.triprecorder.models.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.persistence.*;

import java.security.Principal;
import java.sql.Timestamp;
import java.util.Collection;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@Table(name = "users", schema = "trip_recorder")
@NamedQuery(name = "User.byId", query = "select u from User u where u.id = :userId")
Expand All @@ -17,12 +20,14 @@ public class User implements Principal {
@Basic
@Column(name = "username")
private String username;
@JsonIgnore
@Basic
@Column(name = "password")
private String password;
@Basic
@Column(name = "email")
private String email;
@JsonIgnore
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private Collection<Session> sessions;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UsersResource {
@Produces(MediaType.APPLICATION_JSON)
public User getLoggedUser(@Context ContainerRequest containerRequest){
User user = (User) containerRequest.getSecurityContext().getUserPrincipal();
//TODO: PERCHé NON FAI IL JSON!?!?!?!
user.setTrips(null);
return user;
}
}

0 comments on commit 5a66d00

Please sign in to comment.