HttpClientMock icon indicating copy to clipboard operation
HttpClientMock copied to clipboard

Included JSON matching for body

Open pkalbrun-goeuro opened this issue 6 years ago • 4 comments

Feature request: Include JSON patch matching for request body in the withBody() matcher. Like https://github.com/spotify/java-hamcrest#json-matchers

pkalbrun-goeuro avatar Jul 10 '19 07:07 pkalbrun-goeuro

I guess you mean JSON path :)

HttpClientMock in current version works fine with json-matchers

  HttpClientMock mock = new HttpClientMock();
        mock.onGet("/aaa").withBody(isJsonStringMatching(
            jsonObject().where("foo", is(jsonInt(1)))
            )
        );

Do you need something more?

PawelAdamski avatar Jul 10 '19 08:07 PawelAdamski

Yes, it works perfectly fine. My point was to include it inside library to make it more smooth :)

pkalbrun-goeuro avatar Jul 15 '19 06:07 pkalbrun-goeuro

I've added a PR adding dependency to hamcrest-jackson. However, the more I think about this "improvement", the less appealing whole idea seems to me...

jarst avatar Oct 13 '20 20:10 jarst

Hi @jarst Thanks for contributing to HttpClientMock. I've looked at your PR. I agree that adding dependency is not a big improvement. TBH I rather thought about adding a method like: withBodyHavingJsonField('foo.bar', equal('some test')) Before you start implementation please reach me and consult the proposition.

PawelAdamski avatar Oct 15 '20 07:10 PawelAdamski