Type conversion when using bodyAsJson
See original GitHub issueDescription:
Wiremock changes data types in response fields.
For example: I have following response template:
[
{
"Guid": "77ae335b-5d79-42dc-8ca7-236280ab9111",
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/hello"
}
]
},
"Methods": [
"post"
]
},
"Response": {
"StatusCode": 200,
"BodyAsJson": {
"text": "{{request.bodyAsJson.text}}"
},
"Headers": {
"Content-type": "application/json"
},
"UseTransformer": true
}
}
]
If I am making request with field that containts text then wiremock send my text back as string type as it should be:
"text": "abc" - > "text": "abc"
but if I am making request with field that contains string but it is a number then wiremock responses with the Int type:
"text": "1" -> "text": 1
Expected behavior:
Wiremock does not change data types in response fields.
Test to reproduce
- Use template from example
- Create request with string that contains number (for example:
"test": "1") - Wiremock sends back response -
"test": 1
Other related info
Wiremock version - 1.4.30
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
Which type conversion to use for mixed types (json and ...
One thing you may want to consider is using a header enricher to carry the JSON content in the message headers and the...
Read more >Is it possible to send the Request Body as JSON
I'm using PowerShell so not sure if there is a easy way to convert the parameters needed to xml, but JSON its pretty...
Read more >Type conversion in Java with Examples
Widening conversion takes place when two data types are automatically converted. ... Java Program to Illustrate Automatic Type Conversion.
Read more >Java Json Actions - 2.8.x
Play's actions work with the JsonNode type and the framework provides utility methods for conversion in the play.libs.Json API. §Mapping Java objects to...
Read more >Scala Json Automated - 2.8.x
So, a complete example of performing automated conversion of a case class to JSON ... JSON from request.body.asJson , the request must have...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello @v1le thank you for this issue. I’ll investigate.
(Note that I first thought that this could be related to Handlebars: https://dotnetfiddle.net/b3WCwx, but I think that’s ok.)
@v1le
I see that Scriban does have the method
Evaluatewhich will return the real value, so an int stays an int.See this example: https://dotnetfiddle.net/sZGbaX
However, currently I’m using the
Rendermethod, also for Scriban.So in order to get this working, I need to add a new setting which can switch between Evaluate or Render and then you need to choose Scriban instead of Handlebars.
Maybe this could work, however I’ll not build this in a short time…