Monday, June 29, 2015

Handle keys having dots in JsonPath

When you handle keys having dots in JsonPath,

you can use one of the followings:

// NOTE: 1L doesn't work. Why?
assertThat(JsonPath.<Long> read(metrics, "['counter.test']"), is(1));
assertThat(JsonPath.<Long> read(metrics, "$['counter.test']"), is(1));
assertThat(JsonPath.<Long> read(metrics, "$.['counter.test']"), is(1));

I'm not sure why `<Long>` doesn't work as expected.

It's converted into `Integer`.

You can see a sample in the following:

https://github.com/izeye/samples-spring-boot-branches/blob/rest-and-actuator/src/test/java/samples/springboot/counter/web/CounterControllerTests.java

Reference:
http://stackoverflow.com/questions/19726859/jsonpath-junit-escape-character-for-dots

No comments:

Post a Comment