question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type conversion when using bodyAsJson

See original GitHub issue

Description:

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

  1. Use template from example
  2. Create request with string that contains number (for example: "test": "1")
  3. Wiremock sends back response - "test": 1

Other related info

Wiremock version - 1.4.30

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
StefHcommented, Dec 31, 2021

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.)

0reactions
StefHcommented, Jan 6, 2022

@v1le

I see that Scriban does have the method Evaluate which will return the real value, so an int stays an int.

See this example: https://dotnetfiddle.net/sZGbaX

However, currently I’m using the Render method, 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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found