Figured it out, based on Victory's suggestion of FieldMap.
Interface:
public interface APIMethods {
@FormUrlEncoded
@POST("/api/api/postUser/")
void postUser(
@Header("auth_token") String auth_token,
@FieldMap Map<String, String> userFields,
Callback<RESTResponse> callback
);
}
To convert a User POJO to Map<String, String>
FieldMap, I used Jackson's ObjectMapper:
// Get a REST adapter
RestAdapter restAdapter = RestAdapterFactory.getInstance();
// Create API instance
IAPIMethods methods = restAdapter.create(IAPIMethods.class);
// Define callback
Callback<RESTResponse> callback = new Callback<RESTResponse>() {
@Override
public void success(RESTResponse restResponse, Response response) {
String res = restResponse.responseText;
if(restResponse.status != 1){
Toast.makeText(getBaseContext(), "Error: " + res, Toast.LENGTH_LONG).show();
}else{
textView.setText(res);
}
Log.d("Debug", res);
}
@Override
public void failure(RetrofitError error) {
Log.e("RetrofitError", error.toString());
}
};
// Instantiate User object/bean
User user = new User();
// Set user properties
user.username = "...";
...
// Instantiate Jackson's ObjectMapper to convert User POJO to Map<String, String>
ObjectMapper mapper = new ObjectMapper();
Map<String, String> userFields = mapper.convertValue(user, Map.class);
methods.postUser(API_KEY, userFields, callback);
In PHP, access user data with $_POST and Headers with getallheaders();