You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class EmployeeRequest {
private String name;
private String phone;
private String companyName;
private String abn;
private List licenses;
public EmployeeRequest(String name, String phone, String companyName, String abn, List<License> licenses) {
this.name = name;
this.phone = phone;
this.companyName = companyName;
this.abn = abn;
this.licenses = licenses;
}
public static class License {
private List<File> license;
private int id;
public License(List<File> license, int id) {
this.license = license;
this.id = id;
}
}
}
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);
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 ?
The text was updated successfully, but these errors were encountered: