All,
I'm starting to user RetroFit
for the first time, and it's pretty awesome. That said, I'm running into a road block when formatting a POST request.
The API I'm using specifies that to create a user, I need to send the user object like this:
{
"user": {
"first_name": "John",
"last_name": "Doe",
"email": "john@doe.com",
"password": "jigglypuff123",
"password_confirmation": "jigglypuff123"
}
}
I know that I can send a JsonObject
in this form, but I'd instead like to leverage RetroFit
.
If I pass in a User
object, it doesn't get wrapped in user
. Just
{
"first_name": "John",
"last_name": "Doe",
"email": "john@doe.com",
"password": "jigglypuff123",
"password_confirmation": "jigglypuff123"
}
is sent.
I tried using the @Field
annotation, and ended up with this:
@POST("/users")
void createUser(@Field("user[first_name]") String first, @Field("user[last_name]") String last, @Field("user[email]") String email, @Field("user[password]") String password, @Field("user[password_confirmation]") String password_confirmation, Callback<User> cb);
I ended up with this error:
@Field parameters can only be used with form encoding. (parameter #1)
Does anyone know how to achieve this?