-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot pass null to @Body #1488
Comments
I'm not sure about supporting this. Passing |
Well its a real case, before moving to retrofit we used to form this request with the relevant content-type header if it had body. |
@swankjesse have an opinion here? We support creating an empty body automatically when no |
Reading this it seems converters would never be called for null even if accepted. How should we handle JSON RPC 2.0 where params (so in that case body object) can be omitted ? (Based on https://github.com/segmentio/retrofit-jsonrpc). To have the converter call we need to pass an object but to completely omit the params part we'd need to either add a param or use a specific object and test for it. Is there a better way ? |
@swankjesse ping. got an opinion here? |
@Tolriq We recommend you either use a sentinel value ( |
So we aren't going to make any fundamental changes. I'm going to try and encapsulate all our thinking here.
If you want to create a request with an optional body, we are going to recommend you create an overload without a Remember, while Retrofit offers a lot of flexibility in customizing the service interfaces so that they are easy to use, it is not a high-level interface that can encode every business logic rule of your application layer. Sometimes you need to leverage multiple methods on the service interface conditionally from your application code. If you're using Java 8 default methods work great here, otherwise a helper method or completely abstracting Retrofit interfaces behind a domain-specific API for your application works well here. |
I have a call which gets "@Body RequestBody body"
I dont have always a need to pass body to it nd i cannot use null.
The text was updated successfully, but these errors were encountered: