2017-09-04 6 views
0

내 프로젝트에는 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 엔티티 클래스

+0

모든 요청에 ​​대한 페이로드 표시 pl30 – Cepr0

+0

POST 본문을 설문 조사에 추가했으나 정상적으로 작동하므로 내 문제와 관련이 있다고 생각하지 않습니다. – Dcortez

+1

다른 주제에 대한 내 대답보기 : https://stackoverflow.com/a/46025434 – Cepr0

답변

1

불행히도 문제는 샘플 코드에 포함되지 않은 롬복 주석에 있습니다. 아무도 문제가있는 곳을 볼 수 있도록 지금 추가했습니다.

저는 Lombok을 버전 (1.16.14)으로 다운 그레이드하고 주석 @AllArgsConstructor@AllArgsConstructor(suppressConstructorProperties = true)으로 변경하여 문제를 해결할 수있었습니다. 이 속성은 현재 제거 된 이후 Lombok 버전에서 구현할 수 없습니다.

스프링 데이터 나머지 JIRA에 대한 해결책을 찾았습니다. 문제를 언급하고 해결책/해결 방법을 제시하는 문제는 이미 DATAREST-884입니다.

모든 코드가 없으면 솔루션을 볼 수 없지만 낭비입니다.

+0

이 정보를 보았습니까? https://projectlombok.org/features/configuration'lombok.anyConstructor.suppressConstructorProperties true이면 lombok은 생성자를 생성 할 때 @ java.beans.ConstructorProperties 주석을 생성하지 않습니다. 이것은 GWT와 안드로이드 개발에 특히 유용합니다. " – Cepr0

+0

네,하지만 유스 케이스에 연결하지 않았습니다. 이 주석은 어쨌든 엔티티를 URI에서 비 직렬화 할 수 없게 만듭니다. 그러나 이것이 왜 일어나는지는 내 신비입니다. 이제이 param이 이제 Lombok에서 제거되었을 때, 필자는 사용 사례를 종속성을 다운 그레이드 할 필요없이 어떻게 든 해결해야하는 문제로 간주합니다. – Dcortez