RequestMapping
のリストを返す簡単なUsers
メソッドがあります。Users
モデルにはONE TO MANY
HolidayDates
との関係...ただ遊んでいるので、関係(休日に行った日付のリスト)として休日の日付を選択しました。
したがって、ONE
ユーザーはMANY
関連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;
以下のコードを使用して、すべてのユーザーと関連する休日の日付を検索します:
@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;
}
UserServiceには@autowired
フィールドをuserDao
に追加します。これは、JPAリポジトリを単純に拡張します。
public interface UserDao extends JpaRepository <User, Integer> {
コントローラーでGET
リクエストを実行すると、次のレスポンスが返されます。
Expected ':' instead of 't'
Fasterxml.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]
このjpa/model
からjson
への変換?
User
はHolidayDates
を参照し、HolidayDates
はUser
を参照するため、シリアル化中に無限再帰が行われます。 @JsonIgnore
をgetUser
のHolidayDates
に追加することで停止できます。
@JsonManagedReference
private Set<HolidayDates> holidayDates;
そして
@JsonBackReference
private User user;
私は質問に対する正しい答えがjnyによって受け入れられた答えであることには同意しますが、Spring Bootに悪いJackson objectMapper configをインストールすることでまったく同じ問題を取得しました。何らかの理由で、日付のシリアル化を修正する代わりに、完全に異なるクラス。次のコードを削除すると、再び機能し始めました。誰かが同じ問題を抱えている場合に備えて、これをここに置いてください
@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;
}
あなたのエラーと同じですが、私の場合、デフォルトのコンストラクタを実装していません。
public User() {}
この問題は、エンティティクラス間の無限再帰が古いバージョンでは@JsonIgnoreを使用し、新しいバージョンではこのコードを使用するためです。
@OneToMany(
mappedBy = "queue_group",fetch = FetchType.LAZY,
cascade = CascadeType.ALL
)
@JsonManagedReference
private Set<Queue> queues;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "qid")
// @JsonIgnore
@JsonBackReference
private Queue_group queue_group;
ユーザーモデルに@ JsonManagedReferenceを追加し、HolidayDatesモデルに@ JsonBackReferenceを追加します
ユーザーモデル:
@OneToMany
@JsonManagedReference
private Set<HolidayDates> holidayDates;
HolidayDateモデル:
@ManyToOne
@JsonBackReference
private User user;