mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
How to force a formatted DateTime to return a string? #558
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @felipetofoli on GitHub (Dec 6, 2023).
First of all, thanks for this amazing lib! :)
I have to apply a specific format (
"yyMMddhhmmss") to a DateTime and receive a string as the result. I tried multiple approaches, but I always receive an integer, instead of a string.So my question is: How to force a formatted DateTime to return a string?
Example:
The above JSON configuration returns the following result:
The expected/desired result:
I already tried wrapping the configuration with double quotes, using
String.Appendto append an empty string (""), but I wasn't able to get the expected/desired result.Please let me know if any other information is needed!
Thanks!
@StefH commented on GitHub (Dec 6, 2023):
@felipetofoli
This looks the same as this issue:
https://github.com/WireMock-Net/WireMock.Net/issues/884
I think the only solution for you would be not to use
BodyAsJson, but justBodyand return the required json message as a string.Like:
@StefH commented on GitHub (Dec 6, 2023):
https://github.com/WireMock-Net/WireMock.Net/pull/1029
@StefH commented on GitHub (Dec 7, 2023):
@felipetofoli is this ok for you?
@felipetofoli commented on GitHub (Dec 7, 2023):
Hi @StefH !
Thanks for the response!
Yes, the
Bodyapproach works for the JSON configuration.I am thinking about using C# mappings instead (to avoid the inline configurations).
According to the other issues, the
.WithTransformer(ReplaceNodeOptions.EvaluateAndTryToConvert)should do the trick, right?Reference: https://github.com/WireMock-Net/WireMock.Net/issues/884#issuecomment-1693548031
Or should I use
.WithTransformer(ReplaceNodeOptions.KeepString)?Reference: https://github.com/WireMock-Net/WireMock.Net/issues/884#issuecomment-1432874211
@StefH commented on GitHub (Dec 7, 2023):
I'm not 100% sure anymore if that enim option works as intended
So for now use c# mappings or a body as string.
@felipetofoli commented on GitHub (Dec 7, 2023):
@StefH, I've just tested the c# mappings, but they are returning a number either - instead of a string:
Response:
Is there any other configuration to do?
Thanks,
@StefH commented on GitHub (Dec 7, 2023):
Sorry. In that case : use a string instead of json.
I need to think in how to change the internal logic.