나는 세 가지 요소를 가지고 (사용자) 및 태그 목록이 있습니다.POST "인라인"하위 ressource 협회
프리젠 테이션을 만들거나 업데이트하는 경우 리소스 사용자와 태그를 연결해야합니다. Spring Data Rest - Association Resource의 설명서에 따르면 Content-Type: text/uri-list
헤더를 사용하여 할당 할 수 있습니다. 그러나이 경우 내가 하나가, 같은 태그에 대한 저자을 설정하는 하나의 또 다른, 프리젠 테이션을 만들려면 여러 번 호출 할 필요가 :
curl -i -X POST -H "Content-Type: application/json" -d '{"name": "P1"}' http://localhost:8080/api/presentations
curl -i -X PATCH -H "Content-Type: text/uri-list" -d "
http://localhost:8080/api/users/1" http://localhost:8080/api/presentations/1/author
curl -i -X PATCH -H "Content-Type: text/uri-list" -d "
http://localhost:8080/api/tags/1
http://localhost:8080/api/tags/2" http://localhost:8080/api/presentations/1/tags
을
나는 저자에 대한 별도의 호출을 우회하는 방법을 발견 그리고 어떻게 그 프리젠 테이션 호출의 "인라인"(thanks to Chetan Kokil) :
// WORK:
curl -i -X POST -H "Content-Type: application/json" -d '{"name": "P1", "author": "http://localhost:8080/api/users/1"}' http://localhost:8080/api/presentations
그래서 나에게 추가로 전화를 저장하고 나의 이해에 따라이 ACID 원칙을 따른다.
태그 목록과 동일하게하고 싶습니다.
// DON'T WORK:
curl -i -X POST -H "Content-Type: application/json" -d '{"name": "P1", "author": "http://localhost:8080/api/users/1", "tags":["http://localhost:8080/api/tags/1","http://localhost:8080/api/tags/2"]}' http://localhost:8080/api/presentations
그리고 오류 메시지가 다음 무엇입니까 :
{
"cause": {
"cause": null,
"message": "Can not construct instance of com.example.model.Tag: no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/api/tags/2')\n at [Source: N/A; line: -1, column: -1]"
},
"message": "Could not read payload!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.example.model.Tag: no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/api/tags/2')\n at [Source: N/A; line: -1, column: -1]"
}
내 질문에, 그것은 그 만들 그렇다면, 올바른 구문은 무엇을 할 수 그래서 다음 호출을 시도?
감사합니다. 내가 솔루션 나 자신을 발견 내 질문 :
를 작성하는 동안