Orest
Orest

Reputation: 6748

Spring Data REST: create entity with @DbRef field

I have two entities:

class User {

@DbRef
private Form form; 

}

class Form {
}

And REST repositories @RepositoryRestResource for both of them.

I want to create new User resource, so I'm doing POST request with next json:

{
   "form":"/forms/123"
}

Where "/forms/123" is a resource reference. But it doesn't work. It says "Could not read document: Can not construct instance of User: no String-argument constructor/factory method to deserialize from String value"

Should I enable something to make it work?

Upvotes: 1

Views: 407

Answers (1)

Christoph
Christoph

Reputation: 46

You need to provide the full URL, e.g.

{
   "form": "http://localhost:8080/forms/123"
}

Upvotes: 1

Related Questions