Я вызываю REST API от клиента angular 4, вот код клиента angular:
createQuestion(question: Question): Observable<Question> {
return this.http.post<Question>(API_URL + 'create/question', JSON.stringify(question),
{headers: this.headers});
}
Все значения, доступные в объекте вопроса до этого момента. Но когда управление переходит в RestController:
@RestController
@RequestMapping(AppUtilities.ROOT_MAPPING)
public class QuestionController {
@Autowired
private QuestionService questionService;
@Autowired
private QuizService quizService;
@PostMapping("/create/question")
public Question save(@RequestBody Question question) {
Quiz quiz = quizService.find(question.getQuiz().getId());
question.setQuiz(quiz);
return questionService.save(question);
}
}
все свойства вопроса становятся нулевыми, см. Скриншот:
Вот мой класс модели Вопроса:
@Entity
@Table(name = "question")
public class Question extends BaseModel implements UserOwned {
@Size(min = 2, max = 150, message = "The question should be between 2 and 150 characters")
@NotNull(message = "Question text not provided")
private String text;
@ManyToOne
private Quiz quiz;
@Column(name = "a_order")
private Integer order;
@OneToMany(mappedBy = "question", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Answer> answers;
@OneToOne(cascade = CascadeType.ALL)
private Answer correctAnswer;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false)
private Calendar createdDate;
@JsonIgnore
private boolean isActive;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Quiz getQuiz() {
return quiz;
}
public void setQuiz(Quiz quiz) {
this.quiz = quiz;
}
public Integer getOrder() {
return order;
}
public void setOrder(Integer order) {
this.order = order;
}
public List<Answer> getAnswers() {
return answers;
}
public void setAnswers(List<Answer> answers) {
this.answers = answers;
}
public Calendar getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Calendar createdDate) {
this.createdDate = createdDate;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
@Override
public User getUser() {
return quiz.getUser();
}
public Answer getCorrectAnswer() {
return correctAnswer;
}
public void setCorrectAnswer(Answer correctAnswer) {
this.correctAnswer = correctAnswer;
}
@Override
public String toString() {
return "Question{" +
"text='" + text + '\'' +
", quiz=" + quiz +
", oreder=" + order +
", answers=" + answers +
", correctAnswer=" + correctAnswer +
", createdDate=" + createdDate +
", isActive=" + isActive +
'}';
}
}
Любая помощь будет ощутимой, спасибо заранее.