https://linen.dev logo
#help
Title
# help
m

Marcin Z.

12/13/2023, 8:31 AM
Hi. I've migrated some project from 3.0.0-beta-10 to 3.3.1 (also checked with 3.0.1) and I have problem with response tempting. TL;TR. How to do jsonPath
"tracking": "{{jsonPath request.body '$.tracking'}}"
(without extra quotation in
jsonBody
) where "tracking" is an array ? My mapping:
Copy code
{
  "request": {
    "method": "PUT",
    "urlPathPattern": "/orders/[0-9]+",
    "bodyPatterns": [
      {
        "matchesJsonPath": "$.tracking[*]"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "jsonBody": {
      "id": "{{request.pathSegments.[4]}}",
      "type": "external",
      "tracking": "{{jsonPath request.body '$.tracking'}}"
    },
    "transformers": [
      "response-template"
    ]
  }
}
but I've got (after upgrade) JsonMappingException :
Copy code
... com.fasterxml.jackson.databind.JsonMappingException: {
  "errors" : [ {
    "code" : 10,
    "source" : { },
    "title" : "Error parsing JSON",
    "detail" : "Unexpected character ('1' (code 49)): was expecting comma to separate Object entries\n at [Source: (String)\"{\"id\":\"11111\",\"type\":\"external\",\"tracking\":\"[\"123\",\"345\"]\"}\"; line: 1, column: 48]"
  } ]
It looks that for:
Copy code
{
  "type": "REQUEST",
  "method": "PUT",
  "path": "<http://localhost:8099/orders/11111>",
  "headers": [],
  "body": {
    "status": "readyforshipment",
    "tracking": [
      "123",
      "345"
    ]
  }
}
the generated response was:
Copy code
{"id":"11111","type":"external","tracking":"["123","345"]"}
where
"["123","345"]"
is invalid. How can I use request reference to an array in
jsonBody
to skip surrounding quation marks? Btw, my response is much bigger. I would prefer not to abandon
jsonBody
in favour of
body
. It worked wine with 3.0.0-beta-10.
👀 1
I reported it as a regression: https://github.com/wiremock/wiremock/issues/2533 Simpler example:
"tracking": "{{{array 123 456}}}",
which generates
"tracking":"[123, 456]"
which is not illegal, but incorrect. Just
"tracking":[123, 456]
is expected.
g

Gunjan Basak

12/19/2023, 8:40 PM
@Marcin Z. Thank you for adding detailed info. I tried the reproduction steps. Was this ever working in any previous version? Another note : If you remove the quote from the template, it does not appear in the response. (The json becomes invalid, but it gives the result)
Copy code
{
      "id": "{{request.pathSegments.[4]}}",
      "type": "external",
      "tracking": {{jsonPath request.body '$.tracking'}}
}
m

Marcin Z.

12/21/2023, 10:54 AM
Thanks @Gunjan Basak for taking a look. I tried without quoting, but Wiremock 3.3.1 fails with:
Caused by: java.lang.ExceptionInInitializerError: Exception com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file /.../src/test/resources/mappings/updateOrderTracking.json:
Unexpected character ('{' (code 123)): was expecting double-quote to start field name
Regarding the past, there was definitely no error before, so it seemed work or Wiremock for some reasons was quietly ignoring the errors.
I've re-checked it with the 3.0.0-beta-10 and you were right.
"tracking":"[123, 456]"
is also generated. However, the error is not generated, maybe parsing with the JSON decoder was added after that (and we were asserting that particular in our tests).
👍 1
I wonder, if it is "fixable" with
jsonBody
?
🤔 1
3 Views