I am using Spring Data REST, and I am trying to change a many-to-one relation using Spring REST, but I cannot get the proper http call to work.
My entity looks like this (basic calls like creation with POST etc. works fine):
{ "id" : 70, "productId" : yyy, "productdiscount" : 10, "version" : 0, "description" : "xxx", "_links" : { "self" : { "href" : "http://localhost:8080/rest/rules/70" }, "timedefinition" : { "href" : "http://localhost:8080/rest/rules/70/timedefinition" } } }
I want to change the current timedefinition with say ID 1, to ID 2.
I have tried a lot of different call types with different errors. The below call doesn´t work.
curl -X PUT -H "Content-Type: text/uri-list" -d 'http://localhost:8080/rest/timedefinition/1' http://localhost:8080/rest/rules/70/timedefinition
The following error is received:
Failed to convert from type java.lang.String to type domain.TimeDefinition for value '0'; nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class domain.TimeDefinition. Expected: class java.lang.Integer, got class java.lang.Long
Another example is this:
curl -X PUT -H "Content-Type: application/json" -d '{"timedefinition": {"href" : "http://localhost:8080/rest/timedefinition/0", "rel" : "timedefinition"} }' http://localhost:8080/rest/rules/70/timedefinition
The error I get is:
"message":"Must send only 1 link to update a property reference that isn't a List or a Map."
The main reference at http://docs.spring.io/spring-data/rest/docs/2.0.1.RELEASE/reference/html/ doesn´t give much info on the topic above unfortunetely.
Any insights and explanations on the proper REST query format to update entities assocations are greatly appreciated!