복붙노트

[SPRING] Spring Data REST - 관계가있는 새로운 엔티티 POST

SPRING

Spring Data REST - 관계가있는 새로운 엔티티 POST

스프링 데이터 레스트 버전 2.0.2

설명 : Person 객체에 @ManyToOne (예 : @OneToOne 대신) 관계를 가진 엔티티 (Address)를 POST하려고합니다. 복잡한 객체 그래프의 Embedded Entity references가 있지만 Jackson Error :

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: Address["person"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: Address["person"])
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:228) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]

나는 rel과 href를 가진 JSON 객체를 Address의 "person"속성에 보낼 수 있다는 것이 이상하다는 것을 알았다.

"person": {
    "rel" : "people.Person",
    "href" : "http://localhost:8080/people/1"
}

여전히 유효합니까? 언급 된 페이지는 꽤 오래되었습니다 (2012). 업데이트 된 문서가 있습니까? 나는 최신 (현재까지) 2.1.0 RC1의 경우에도 참조 문서를 검토했지만 부족함을 발견했습니다.

모든 포인터가 인정 될 것이다.

Stackoverflow 내 질문에, 내 경우에는 HTTP 상태 405 - 요청 방법 'POST'지원되지 않습니다 ...이 문제를 볼 것을 제안했다 ... 아마도 구성 문제가 있지만 내 원래 질문.

업데이트 1 : 참조 문서 섹션 4.1에서 다음과 같이 말합니다 :

문제는 내가 최대 절전 모드 지원과 함께 사용자 지정 Jackson ObjectMapper를 사용하고있는 것일 수 있습니다. 나는 더 파헤 치려고 노력할 것이다.

업데이트 2 : 업데이트 1을 신경 쓰지 말고, Hibernate4Module을 제거했고 동작은 동일합니다.

해결법

  1. ==============================

    1.링크 된 페이지의 형식이 오래되었습니다. 방금 업데이트했습니다. 올바른 형식은 다음과 같습니다.

    링크 된 페이지의 형식이 오래되었습니다. 방금 업데이트했습니다. 올바른 형식은 다음과 같습니다.

    {
        "postalCode": "12345",
        "province": "MO",
        "lines": ["1 W 1st St."],
        "city": "Univille",
        "person": "http://localhost:8080/people/1"
    }
    

    적어도, 이것은 내 사업체와 함께 저에게 효과적입니다.

  2. from https://stackoverflow.com/questions/23767233/spring-data-rest-post-new-entity-with-relationships by cc-by-sa and MIT license