-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Java Spring RestTemplate] Could not write request: no suitable HttpMessageConverter exception when using client #513
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
Comments
@MatanRubin I guess you are missing the jackson message converter, see http://forum.spring.io/forum/spring-projects/android/126794-no-suitable-httpmessageconverter-found |
@macjohnny , thanks for the quick reply.
As you can see, I also tried debugging right to the point where RestTemplate was trying to use the converter. It seems that the issue is more related to the fact that it tries to convert "request type [java.lang.Object]", and less with the fact that it tries to convert to "content type [application/json]". Do you know why the request type is |
It is a problem in the library. The error was inserted in this commit (0fb1ffa#diff-8476983adf7dcdaf957e0aed45e5c8b4) on June 7th (pull request #98). Instead of having a null post body in operations not accepting a body (like GET), now a plain This behavior needs to be rolled back or fixed. |
…form HTTP requests without a body and an empty Object is used as body instead. In these cases an exception is thrown indicating that it is not possible to find a message converter for java.lang.Object and application/json.
I just created the #605 pull request in order to get this issue fixed. In it I suggest to use null, as default, for POST body only for RestTemplate, whose behavior gets broken as message converters are not able to properly convert ´java.lang.Object´. |
When I read the description of #98:
It comes to my mind that I have started to work on #476. There the use case is that if there is no body (which I guess is the case when it is Feel free to comment on #476 if you think this is a good idea. |
Is this fixed by merge of PR #605 ? |
@jmini, I have just launched a code generation using https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator/3.1.2-SNAPSHOT/openapi-generator-3.1.2-20180724.111208-30.jar and, indeed, the error is not reproduced anymore. @MatanRubin, could you please confirm? |
I have just tested this using version 3.1.2 and I confirm the issue I saw is now resolved. Thanks a lot for the quick resolution! On a side note - this was a serious bug in a very basic scenario for a very common library (i.e. the generated client fails a simple GET for Java + RestTemplate). Don't we have tests that cover this kind of scenarios for all languages and libraries? Not trying to blame anyone here, just asking out of curiosity and to see maybe I can contribute some tests that will help prevent this kind of issues. |
@MatanRubin : I have opened an other issue to discuss your tests question: #689 I would appreciate some feedback there. |
…penAPITools#605) OpenAPITools#513 Fixed error that causes exception when trying to perform HTTP requests without a body and an empty Object is used as body instead. In these cases an exception is thrown indicating that it is not possible to find a message converter for java.lang.Object and application/json.
Description
I have generated a Java RestTemplate client using the sample PetStore API. I compiled and installed the client, then used it from a Spring Boot 2.0.3 application like this:
My configuration:
The code that uses the client:
This caused the following exception:
openapi-generator version
3.0.2
OpenAPI declaration file content or url
The sample Pet Store API:
https://github.com/raw/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml
Command line used for generation
Followed the instruction on the main README file with the
java
language andresttemplate
generator.Steps to reproduce
Here's a sample project that shows the issue:
demo-6.zip
To see the issue, unpack the zip and:
The text was updated successfully, but these errors were encountered: