0

I want to to make a POST request using Retrofit. My POST request has a body which is complex data like this

{
    "user": {
        "personal_info": {
            "first_name": "Walter",
            "last_name": "White",
            "date_of_birth": "1972-01-03 00:00:00 PST"
        },
        "address_info": {
            "address_1": "308 NEGRA ARROYO LANE",
            "address_2": "#",
            "city": "ALBUQUERQUE",
            "state": "NM",
            "zip_code": "87104"
        },
        "contact_info": {
            "email": "wwhite@test.com",
            "telephone": "88888888888",
            "telephone_type_id": 1
        },
        "employment_info": {
            "employer_name": "SELF",
            "employment_status_id": 7,
            "annual_income": 9000000000000000,
            "monthly_income": 750000000000,
            "employment_start_year": 0,
            "employment_start_month": 0
        }
    }
}

I have the interface defined as

@POST("/users")
void user(@Body User User, Callback<User> cb);

I am not sure how my User class should look like, I want the payload to be same as mentioned above, I Am confused how to send this type of data server and how to store data in user class

Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92
Developer
  • 21
  • 4

1 Answers1

0

You don't need to think about the structure provided as a Json response.

Just use some smart tools like jsonscheme2pojo will automatically generate the class files for you.

you just need to visit the site and configure your requirement like package name, class name, set target language JAVA, source type JSON , annotation style Gson and then click on Zip button (You can also see the preview by click on preview button).

After click on Zip button the zip will be downloading automatically. extract the zip and you will find your class files.

Android Dev
  • 1,496
  • 1
  • 13
  • 25