J'ai une simple méthode RequestMapping
qui retourne une liste de Users
, le modèle Users
ayant une relation ONE TO MANY
avec HolidayDates
... Je me suis juste amusé avec elle, alors j'ai choisi les dates de vacances comme relation (liste de dates ils sont partis en vacances).
Donc, ONE
utilisateur peut avoir MANY
lié Dates
.
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="userId")
private int userId;
@Column(name="about")
private String about;
// Maybe change to fetchtype eager
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "holidayDates")
private Set<HolidayDates> holidayDates;
public void setHolidayDates(Set<HolidayDates> holidayDates) {
this.holidayDates = holidayDates;
}
public Set<HolidayDates> getHolidayDates() {
return holidayDates;
}
...Other setters and getters
@Entity
@Table(name="holiday_dates")
public class HolidayDates {
//
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="holidayId")
private int holidayId;
@Column(name="start_date")
private String startDate;
@Column(name="end_date" )
private String endDate;
@ManyToOne
@JoinColumn(name = "userId")
private User user;
Quand je vais trouver tous les utilisateurs et leurs dates de vacances, en utilisant le code ci-dessous:
@RequestMapping(value="{name}", method=RequestMethod.GET)
public @ResponseBody List<User> user(@PathVariable String name) {
List<User> user = userService.findAll();
// Simply implementing List<User> findAll(); from userService auto wired field
return user;
}
Le service utilisateur a un champ @autowired
à userDao
, qui étend simplement le référentiel JPA:
public interface UserDao extends JpaRepository <User, Integer> {
Maintenant, lorsque j'exécute une requête GET
sur le contrôleur, la réponse suivante est renvoyée:
Expected ':' instead of 't'
En plus d'une trace longue et longue de la pile d'erreurs Fastxml.jackson:
[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.Java:675) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.Java:157) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.Java:149) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:111) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.Java:24) ~[jackson-databind-2.6.6.jar:2.6.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.Java:693) ~[jackson-databind-2.6.6.jar:2.6.6]
Spring ne gère-t-il pas toutes ces conversions de jpa/model
à json
?
Vous avez une récursion infinie pendant la sérialisation puisque User
fait référence à HolidayDates
et HolidayDates
à User
Vous pouvez l'arrêter en ajoutant @JsonIgnore
à getUser
dans HolidayDates
.
@JsonManagedReference
private Set<HolidayDates> holidayDates;
et
@JsonBackReference
private User user;
Bien que je convienne que la réponse correcte à la question est la réponse acceptée par jny, j’ai exactement le même problème en faisant installer une mauvaise configuration Jackson objectMapper dans Spring Boot qui, pour une raison quelconque, au lieu de corriger la sérialisation des dates classe entièrement différente. J'ai supprimé le code suivant et les choses ont recommencé à fonctionner. Il suffit de mettre ceci ici au cas où quelqu'un aurait le même problème
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
// objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
return objectMapper;
}
Identique votre erreur, mais dans mon cas car je manque le constructeur implémenter par défaut.
public User() {}
add @JsonManagedReference dans votre modèle d'utilisateur et @JsonBackReference pour le modèle HolidayDates
Modèle d'utilisateur:
@OneToMany
@JsonManagedReference
private Set<HolidayDates> holidayDates;
Modèle HolidayDate:
@ManyToOne
@JsonBackReference
private User user;