I'm using Retrofit in my Android app to do a couple of HTTP requests. The first is to get all the information in a specific table (this is working and the fields are being deserialized properly). The second is to insert a new row into that same table. When inserting into the table, all my data appears blank in the DB (my strings are "" and my integers are 0s). When I insert manually using Postman, everything inserts fine. I have inspected the object that I'm sending in the request and all the data is populated correctly.
Here is my interface:
public interface FormRequests {
@POST("/createForm.php")
public Call<Response> CreateForm(@Body Form form);
@POST ("/getAllForms.php")
public Call<ArrayList<Form>> GetAllForms();
}
Here is where I'm trying to insert the form:
Retrofit retrofit = new Retrofit.Builder().baseUrl(DatabaseConstants.URL).addConverterFactory(GsonConverterFactory.create()).build();
FormRequests service = retrofit.create(FormRequests.class);
final Call<Response> call = service.CreateForm(form);
new Thread(new Runnable() {
@Override
public void run() {
try {
retrofit.Response<Response> response = call.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Here is the JSON from the insert when I pull all the table data:
[{"id":"5","date":"","miles":"0","rate":"0","ticket_number_1":"0","quantity_1":"0","lease_number_1":"0","amount_1":"0","ticket_number_2":"0","quantity_2":"0","lease_number_2":"0","amount_2":"0","total_quantity":"0","fuel_percent":"0","fuel_price":"0","ip_minutes":"0","ip_charge":"0","lp_minutes":"0","lp_charge":"0","other_fees_1":"0","other_fees_reason_1":"","other_fees_2":"0","other_fees_reason_2":"","remarks":"","ip_wait_reason":"","lp_wait_reason":"","company":"","driver":"","truck":"","trailer":""}]
EDIT: Here's some more information of what my server is seeing. I logged the SQL command when I use Postman and then my app, respectively:
INSERT INTO `database`.`forms` (`date`, `miles`, `rate`, `ticket_number_1`, `quantity_1`, `lease_number_1`, `amount_1`, `ticket_number_2`, `quantity_2`, `lease_number_2`, `amount_2`, `total_quantity`, `fuel_percent`, `fuel_price`, `ip_minutes`, `ip_charge`, `lp_minutes`, `lp_charge`, `other_fees_1`, `other_fees_reason_1`, `other_fees_2`, `other_fees_reason_2`, `remarks`, `ip_wait_reason`, `lp_wait_reason`, `company`, `driver`, `truck`, `trailer`) VALUES ('11/13/2015', '500', '1.16', '2342424', '12.50', '211422', '10.50', '90897','29.50', '249023', '49.20', '23483.60', '24.12', '2023.23', '23', '23.3', '39', '29.5', '65.3', 'Tank Refusal', '98.90', 'Rough Road', 'This is my remark and it is awesome', 'The tank was refused', 'The tank was not refused', 'Windy Truck LLC', 'Al Johnson', '227 ROF', 'T02');
INSERT INTO `database`.`forms` (`date`, `miles`, `rate`, `ticket_number_1`, `quantity_1`, `lease_number_1`, `amount_1`, `ticket_number_2`, `quantity_2`, `lease_number_2`, `amount_2`, `total_quantity`, `fuel_percent`, `fuel_price`, `ip_minutes`, `ip_charge`, `lp_minutes`, `lp_charge`, `other_fees_1`, `other_fees_reason_1`, `other_fees_2`, `other_fees_reason_2`, `remarks`, `ip_wait_reason`, `lp_wait_reason`, `company`, `driver`, `truck`, `trailer`) VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
I also just ran my form through GSON, to see if it can be converted into JSON, and this is what I get:
{"amount_1":"15.16","amount_2":"12.33","company":"Windy Truck LLC","date":"11/14/2015","driver":"Al Johnson","fuel_percent":"23","fuel_price":"234.00","ip_charge":"245.00","ip_minutes":"270","ip_wait_reason":"This is a wait reason","lease_number_1":"100","lease_number_2":"1234123","lp_charge":"332.50","lp_minutes":"345","lp_wait_reason":"This is another wait reason","miles":"200","other_fees_1":"343.00","other_fees_2":"233.00","other_fees_reason_1":"Rough Road","other_fees_reason_2":"Split Load","quantity_1":"65.16","quantity_2":"890.16","rate":"5.53","remarks":"This is a remark","ticket_number_1":"50","ticket_number_2":"16549","total_quantity":"2,342.64","trailer":"03","truck":"227 ROF"}
Everything there looks fine, but it looks like Retrofit isn't creating the right GSON object, but I'm not sure if that can happen.
I've searched Google/stackoverflow, but can't find anything pertaining to this. Any suggestions would be great because I don't know how to troubleshoot Retrofit very well.