Theodor Franke
09/27/2024, 1:52 PM{
"priority": 1000000,
"request": {
"method": "POST",
"url": "/authServiceMock",
"bodyPatterns": [
{
"equalToJson": {
"Benutzer": "${json-unit.any-string}"
}
}
]
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"permissions": [
"Start",
],
"Benutzer": "{{{ jsonPath request.body '$.Benutzer' }}}"
}
}
}
This works fine, but when i send a username with a backslash (like domain\\user1
) to the endpoint i get this error from wiremock:
HTTP ERROR 500 wiremock.com.fasterxml.jackson.databind.JsonMappingException: { "errors" : [ { "code" : 10, "source" : { }, "title" : "Error parsing JSON", "detail" : "Unexpected character ('s' (code 115)): expected a hex-digit for character escape sequence\n at [Source: (String)\"{\"permissions\":[\"Start\"],\"Benutzer\":\"domain\\user1\",\"Anwendung\":17}\"; line: 1, column: 46]" } ] } (through reference chain: com.github.tomakehurst.wiremock.http.ResponseDefinition["jsonBody"])
I tried escaping the Benutzer
part but had no luck. Is there any way to solve this problem?
The wierd thing is that if I request with the Benutzer domain\\\\user1
I dont get an error and in the response the String is set to domain\\user1
Rafe Arnold
09/27/2024, 2:17 PMRafe Arnold
09/27/2024, 2:20 PM{{ toJson (jsonPath request.body '$.Benutzer') }}
but i think that will create double quotes on the string valueRafe Arnold
09/27/2024, 2:21 PM{{ cut (toJson (jsonPath request.body '$.Benutzer')) '"' }}
to cut the inner quotes outTheodor Franke
09/27/2024, 2:21 PM{{ regexExtract request.body '\"Benutzer\":\"([^\"]+)\"' 'parts' }}{{ parts.0 }}
solved the issue for nowTheodor Franke
09/27/2024, 2:22 PMcould not find helper: 'toJson'
Rafe Arnold
09/27/2024, 2:22 PM