Helper to parse string to integer

713 views
Skip to first unread message

Nilima Mohabansi

unread,
Aug 8, 2022, 2:48:57 AM8/8/22
to wiremock-user
Hi Team,

I am facing issue where Length=(jsonPath request.body  '$.param') is returning string instead of integer.
is there any helper to parse string to integer.

e.g.
{{randomValue length=33 type='ALPHANUMERIC'}}

Thanks,
Nilima

Tom Akehurst

unread,
Aug 8, 2022, 5:45:29 AM8/8/22
to wiremock-user
Slightly hacky, but you can use the math helper to do the conversion:

{{{randomValue length=(math 0 '+' (jsonPath request.body '$.otpParams')) type='ALPHANUMERIC'}}}

Nilima Mohabansi

unread,
Aug 8, 2022, 8:28:42 AM8/8/22
to Tom Akehurst, wiremock-user
Thank you much. Works :)

BTW i wanted to implement one custom helper for wiremock in java. (any working code or link where we can follow the implementation as how call custom helper ). I explored but everywhere its in bits n pieces.

Appreciate the response.

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "wiremock-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wiremock-user/rknuuhNiwn8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wiremock-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/755d3f40-0b16-4612-af66-e30f03729465n%40googlegroups.com.

Tom Akehurst

unread,
Aug 8, 2022, 9:05:51 AM8/8/22
to wiremock-user
You can pass additional helpers to the ResponseTemplateTransformer constructor when initialising WireMock e.g.

new WireMockServer(wireMockConfig()
  .extensions(new ResponseTemplateTransformer(false, "myHelper", new HandlebarsHelper<Object>() {
    @Override
    public Object apply(Object context, Options options) {
      return "do some helper logic";
    }
})));


(Obviously you don't need to inline everything as I have - just showing it that way for brevity)
Reply all
Reply to author
Forward
0 new messages