Я пытаюсь отправить через json Вопрос, называющий мою конечную точку, но он спрашивает у меня идентификатор, и я не знаю, что делать, чтобы избежать этого, я читал о @JsonIgnore, но я не знаю, так ли этоспособ сделать это.
Это моя модель:
@Entity(name = "question")
public class Question extends DateAudit {
@Id
@Column(name = "question_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
@SequenceGenerator(name = "question_seq", allocationSize = 1)
private Long id;
@Column(name = "text_question")
private String textQuestion;
@Column(name = "answer_description")
@NotBlank(message = "Answer description")
private String answer_description;
@Column(name = "is_exam_question", nullable = false)
private Boolean is_exam_question;
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private Set<Answer> answers;
@Column(name = "answer_type", nullable = false)
private String answerType;
public Question(String text_question, String answer_description, String answerType, Set<Answer> answerSet, Boolean is_exam_question) {
super();
this.textQuestion = text_question;
this.answer_description = answer_description;
this.answers = answerSet;
this.answerType = answerType;
this.is_exam_question = is_exam_question;
}
//Getters
}
И это моя конечная точка
@PostMapping("/create")
@PreAuthorize("hasRole('ADMIN')")
@ApiOperation(value = "Allows the teacher to create a question and add it to the repository")
public ResponseEntity<?> createQuestion(@Valid @RequestBody Question questionRequest) {
if (questionService.existQuestion(questionRequest) != null) {
//Question already exists
return ResponseEntity.ok(new ApiResponse("Question already exist on your repository", false));
} else {
questionService.create(
questionRequest.getText_question(),
questionRequest.getAnswer_description(),
questionRequest.getAnswerType(),
questionRequest.getAnswers(),
questionRequest.getIs_exam_question()
);
}
return ResponseEntity.ok(new ApiResponse("Question added successfully", true));
}
Я сгенерировал чванство, и он запрашивает эти значения:
{
"answerType": "string",
"answer_description": "string",
"answers": [
{
"answer_to_question": "string",
"createdAt": "2019-03-01T16:44:05.102Z",
"id": 0,
"updatedAt": "2019-03-01T16:44:05.102Z"
}
],
"createdAt": "2019-03-01T16:44:05.102Z",
"id": 0,
"is_exam_question": true,
"text_question": "string",
"updatedAt": "2019-03-01T16:44:05.102Z"
}
Как создать вопрос без добавления этих идентификаторов?Но при получении вопроса я бы хотел получить идентификатор.