Open
Description
Arraylist of objects inside object there is file and id how to send this type of request in retrofit 2.0 ?
{
name:Employee one
phone:9876543210
companyName:ows
abn:ows1234
licenses[0].license[0] file
licenses[0].license[1] file
licenses[0].id:1
}
how to send above type of request in android retrofit 2 ?
Activity
tomridder commentedon Apr 2, 2023
public class EmployeeRequest {
private String name;
private String phone;
private String companyName;
private String abn;
private List licenses;
}
public interface MyApiService {
@post("employee")
Call createEmployee(@Body EmployeeRequest employeeRequest);
}
// create a Retrofit instance
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://example.com/api/")
.build();
// create an instance of the MyApiService interface
MyApiService apiService = retrofit.create(MyApiService.class);
// create a list of files
List licenseFiles = new ArrayList<>();
licenseFiles.add(new File("path/to/file1"));
licenseFiles.add(new File("path/to/file2"));
// create a License object
EmployeeRequest.License license = new EmployeeRequest.License(licenseFiles, 1);
// create a list of License objects
List<EmployeeRequest.License> licenses = new ArrayList<>();
licenses.add(license);
// create an instance of the EmployeeRequest class
EmployeeRequest employeeRequest = new EmployeeRequest("Employee one", "9876543210", "ows", "ows1234", licenses);
// make the API call
Call call = apiService.createEmployee(employeeRequest);
parthbagda211 commentedon May 30, 2025
if is it still open, i would like pick this bug!!