Is your feature request related to a problem? Please describe.
I'm working against a REST Api that (sadly) only returns XML formatted responses and I wanted to use UnirestMock in my tests, notably the thenReturn(Object pojo) method.
Alas, that can not work as, like the title says, the thenReturn(Object pojo) method serializes the provided Object pojo to a JSON string as the response's body:
|
this.response = new JsonObjectMapper().writeValue(pojo); |
The Unirest instance I'm mocking in my tests has been configured to use Jackson XmlMapper, thus when processing the MockRawResponse to produce an ObjectResponse:
|
.map(s -> getBody(s, e -> om.readValue(e, to))) |
It fails due to a parsing exception:
"com.fasterxml.jackson.core.JsonParseException: Unexpected character '{' (code 123) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]"
And of course it does: my ObjectMapper expects some XML and is provided JSON instead
As a consequence, the body of the response is null and my test fails.
Describe the solution you'd like
I'd like to be able to somehow provide a custom ObjectMapper to a MockClient instance, that will be used when serialiazing POJOs.
Something like (or anything else that makes more sense):
this.instanceMock = MockClient.register(this.customInstance, new CustomObjectMapper());
Describe alternatives you've considered
Of course, I could simply the XML I want to see returned as a String argument to the `thenReturn(String body) but... I'd very much like not to do that 😅
(I'll do that in the meantime, though, but still)
Is your feature request related to a problem? Please describe.
I'm working against a REST Api that (sadly) only returns XML formatted responses and I wanted to use UnirestMock in my tests, notably the
thenReturn(Object pojo)method.Alas, that can not work as, like the title says, the
thenReturn(Object pojo)method serializes the providedObject pojoto a JSON string as the response's body:unirest-java/unirest-mocks/src/main/java/kong/unirest/Invocation.java
Line 75 in 685d8f8
The Unirest instance I'm mocking in my tests has been configured to use Jackson XmlMapper, thus when processing the
MockRawResponseto produce anObjectResponse:unirest-java/unirest/src/main/java/kong/unirest/ObjectResponse.java
Line 41 in 685d8f8
It fails due to a parsing exception:
As a consequence, the body of the response is
nulland my test fails.Describe the solution you'd like
I'd like to be able to somehow provide a custom ObjectMapper to a
MockClientinstance, that will be used when serialiazing POJOs.Something like (or anything else that makes more sense):
Describe alternatives you've considered
Of course, I could simply the XML I want to see returned as a String argument to the `thenReturn(String body) but... I'd very much like not to do that 😅
(I'll do that in the meantime, though, but still)