Search code examples
androidretrofit2multipartform-datamultipart

nested multipart request using retrofit


I need to make a request which is in nested multipart data. I need to send image in multi part form data and other details should also be in multipart. My Json request is as follow:

{
  "emailId": "vision.jav@avenger.com",
  "phoneNumber": "7417385811",
  "profileImage": "image",
  "password": "12345678",
  "customerDetails": {
    "firstName": "vison",
    "lastName": "vision"
  },
  "addressDetails": {
    "city": "chicago",
    "province": "NY",
    "postalCode": "654987",
    "latitude": "28.52",
    "longitude": "77.54"
  },
  "userRole": {
    "role": "CUSTOMER"
  }
}

Solution

  • For reference ,I am posting the answer. I don`t know how json object are being mapped at backend. Finally, I found the solution afer so many tries. Its working for me. For the above posted request , just use a dot(.) along with inner json object for making keys as Follows.

    1. For inserting data for firstName, Use "customerDetails.firstName" as key.
    2. similarly for last name use "customerDetails.lastName" as key .