Ali Ahmed
Ali Ahmed

Reputation: 2455

How to send optional parameters in retrofit2?

I am using retrofit to send calls to my own api, and in the section of editting person profile, the user maybe doesn't want to modify every single information about him, so I want to send parameters as optional so in my api when the parameter is empty I want not to modify it in the database. anyone tried to do that? how? THANKS FOR ALL.

Upvotes: 2

Views: 4005

Answers (2)

Akaki Kapanadze
Akaki Kapanadze

Reputation: 2672

You can use @FieldMap:

... things(@FieldMap Map<String, Object> params);

Create a HashMap<String, Object> and add all your dynamic params into it and pass the HashMap to the FieldMap params.

Upvotes: 1

Sonia
Sonia

Reputation: 516

Check out this tutorial on optional query parameters:

https://futurestud.io/tutorials/retrofit-optional-query-parameters

The short answer is that you can simply pass null as a parameter when you don't want to pass a value.

Upvotes: 1

Related Questions