-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
MalformedJsonException is thrown is thrown if a response does not have Content-Type header #1013
Comments
Adding some support on the discussion: HTTP RFC Item 7.2.1 |
This is a regression, it should treat it as |
Version 4.0.7 has been released with this change |
@uglyog
|
This change 4.0.6 -> 4.0.7 resulted that the tests started to fail. |
…e is not provided When the body is of type json use the application/json content type Breaking change was between pact 4.0.6 -> 4.0.7
…t-content-type #1013 - Fix to issue when in pact contract content type is not provided
4.0.8 released |
When the body is of type json use the application/json content type Breaking change was between pact 4.0.6 -> 4.0.7 (cherry picked from commit d1b192a)
I'm having a very similar issue when the response type produced by the mock controller is not a JSON but a text/csv. I'm using pact-jvm 4.1.6 version.
Any idea how to solve this? |
@stardust20 you need to provide the content type of the body if it is not JSON. |
I'm sending the accept header, I tried text/plain and text/csv but it doesn't make a difference. The contract in this case looks like the following:
And the response that looks as follows:
The method in the controller I'm mocking has the following mapping:
|
I think the issue here is that the mock controller is not setting up the response content-type, and that causes the error with pact:
And then the error:
|
@stardust20 I can't replicate that error. My test works if the controller sets the content type, and fails if it does not. It looks like Springboot is setting the content type to See https://github.com/pact-foundation/pact-jvm/blob/v4.1.x/provider/spring/src/test/java/au/com/dius/pact/provider/spring/BookController.java#L46 and https://github.com/pact-foundation/pact-jvm/blob/v4.1.x/provider/spring/src/test/resources/pacts/readers-contract.json#L82 |
My controller had a very similar configuration to that one, with the I don't understand why it didn't work with the other setup. In any case, thanks for your help! |
I test a API that does not have Content-Type header by pact.
ProviderClient treats its response body as
application/json
and failed to parse.I think the should be treated as
application/octet-stream
by default.https://github.com/DiUS/pact-jvm/blob/master/provider/pact-jvm-provider/src/main/kotlin/au/com/dius/pact/provider/ProviderClient.kt#L363-L367
The text was updated successfully, but these errors were encountered: