내 프로젝트에는 2 개의 엔티티가 있습니다. 설문 조사 및 설문 조사. 그들은 일대일 관계에 있습니다 (thare는 한 설문 조사에 많은 항목이 될 수 있음). 스프링 데이터 나머지 및 롬복 - 관계 추가 중 예외 발생
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "surveys")
@TypeDef(name = "Survey", typeClass = Survey.class)
public class SurveyEntity extends AbstractEntity {
@NonNull
@Type(type = "Survey")
@Column(name = "template")
// JSON db column type mapped to custom type
private Survey survey;
@OneToMany(mappedBy = "survey")
private List<SurveyEntryEntity> entries;
}
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "survey_entries")
@TypeDef(name = "SurveyEntry", typeClass = SurveyEntry.class)
public class SurveyEntryEntity extends AbstractEntity {
@ManyToOne
@JoinColumn(name = "survey_id")
private SurveyEntity survey;
@NonNull
@Type(type = "SurveyEntry")
@Column(name = "responses")
// JSON db column type mapped to custom type
private SurveyEntry responses;
}
는 또한 봄 데이터 나머지를 사용하여이 개 나머지 저장소 만든 : 나는 성공적으로 나머지 POST 요청에 의해 설문 조사를 추가 한
@RepositoryRestResource(collectionResourceRel = "survey_entries", path = "survey-entries")
public interface SurveyEntryRepository extends PagingAndSortingRepository<SurveyEntryEntity, Long> {
}
@RepositoryRestResource(collectionResourceRel = "surveys", path = "surveys")
public interface SurveyRepository extends PagingAndSortingRepository<SurveyEntity,Long> {
}
을 나는 (이 엔트리에 액세스 할 수 있습니다 현재 비어 있음)을 /api/surveys/1/entries
으로 보내주십시오. 이제는 기존 설문 조사에 항목을 추가하고 싶습니다. 그리고 /api/survey-entries
에 POST (아래 내용)를 보내서 추가 할 수는 있지만 설문 조사 참조로 직접 추가하는 데 문제가 있습니다. 동일한 내용의 url 및 /api/surveys/1/entries
의 POST 메서드를 사용하고 있습니다. 흥미로운 점은 로그에서 NullPointerException이 발생하고 항목이 삽입되지 않았지만 설문 조사에서 감사 수정 타임 스탬프가 변경되었습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 동일한 구성을 놓친 적이 있습니까? 아니면 다른 콘텐츠를 사용해야합니까? 항목과 POST의
내용 :
{
"survey": {
//survey structure
}
}
예외 :
08:41:14.730 [http-nio-8080-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Failed to resolve argument 1 of type 'org.springframework.data.rest.webmvc.PersistentEntityResource'
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: No content to map due to end-of-input; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
@EDIT
조사와 POST의{
"responses": {
"question1": "response1",
"question2": "response2",
"question3": "response3"
}
}
내용 0
내가 '응용 프로그램/복도 + JSON'의 Content-Type 헤더와 아래 내용 /api/survey-entries
에 POST로 항목을 추가하려고했지만, 지금은 다른 예외를 받고 있어요 :
내용 :
{
"survey" : "http://localhost:8080/api/surveys/1",
"responses": {
"question1": "response1",
"question2": "response2",
"question3": "response3"
}
}
을
예외 :
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.domain.SurveyEntity` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/api/surveys/1')
at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 41] (through reference chain: com.domain.SurveyEntryEntity["survey"])
@Edit 2
라이트 람 주석 O 본 n 엔티티 클래스
모든 요청에 대한 페이로드 표시 pl30 – Cepr0
POST 본문을 설문 조사에 추가했으나 정상적으로 작동하므로 내 문제와 관련이 있다고 생각하지 않습니다. – Dcortez
다른 주제에 대한 내 대답보기 : https://stackoverflow.com/a/46025434 – Cepr0