Is parsing through JSON response with a String path intentionally case insensitive?

360 views
Skip to first unread message

Kelsey Shimada

unread,
Sep 16, 2016, 8:40:08 AM9/16/16
to REST assured
My team has recently run into an issue with one of our tests where a field in the JSON response changed case, which broke our serialization, but the test did not fail -- thus, we were not warned about this potential issue. For example, let's say that our test has the following body assert method:

...assertThat().body("payload.foo.bar", notNullValue());

If we decided to change the payload to now read "payload.foo.BAR", I would expect the untouched test to fail, given that it shouldn't be able to find a path that matches "payload.foo.bar" anymore.

Are we missing something, or is this check intentionally case insensitive?

Johan Haleby

unread,
Sep 16, 2016, 8:46:12 AM9/16/16
to rest-a...@googlegroups.com
Hmm good question, I wasn't aware of this so I would definitely say that it's unintentional and (probably) a bug! I've always assumed JSON to be case sensitive but to be honest I'm not 100% sure. A quick google search didn't give me much clues either. Do you have know anything more on this?

/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johan Haleby

unread,
Sep 16, 2016, 9:32:41 AM9/16/16
to rest-a...@googlegroups.com
I've tried to reproduce this but I fail to do so. In my tests the path is indeed case sensitive. What version of REST Assured are you using?

Kelsey Shimada

unread,
Sep 16, 2016, 2:40:57 PM9/16/16
to REST assured
Oh hmm it looks like we are on 2.5.0. Unfortunately, I don't know much more than you (I too did as many Google searches as I could think of regarding this issue), but it sounds like if you cannot repro, it's either the version or our own implementation of REST Assured. I'll look into getting us up-to-date.

Thank you so much for the quick response!
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Johan Haleby

unread,
Sep 16, 2016, 3:21:47 PM9/16/16
to rest-a...@googlegroups.com
I've tried version 2.8.0 and 3.0.1 and it works in both for me. Tell us if you find out what could be causing this for you.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Sent from my phone

Kelsey Shimada

unread,
Sep 16, 2016, 3:34:00 PM9/16/16
to REST assured
I realized that my example in my first post is not indicative of the actual issue, and I think I've finally narrowed it down. If the JSON response looks like this:

{
"lotto":{
 "lottoId":5,
 "winning-numbers":[2,45,34,23,7,5,3],
 "winners":[{
   "winnerId":23,
   "numbers":[2,45,34,23,3,5]
 },{
   "winnerId":54,
   "numbers":[52,3,12,11,18,22]
 }]
}
}

Then the following two calls to the body method seem to function identically:

...body("lotto.winners.winnerId", hasItems(23, 54))

and

...body("lotto.winners.WINNERID", hasItems(23, 54))

However, if you try to do something like ...body("lotto.WINNERS", notNullValue()) -- this will fail. 

Johan Haleby

unread,
Sep 17, 2016, 1:01:34 AM9/17/16
to rest-a...@googlegroups.com
On Fri, Sep 16, 2016 at 9:34 PM, Kelsey Shimada <kelsey....@redfin.com> wrote:
I realized that my example in my first post is not indicative of the actual issue, and I think I've finally narrowed it down. If the JSON response looks like this:

{
"lotto":{
 "lottoId":5,
 "winning-numbers":[2,45,34,23,7,5,3],
 "winners":[{
   "winnerId":23,
   "numbers":[2,45,34,23,3,5]
 },{
   "winnerId":54,
   "numbers":[52,3,12,11,18,22]
 }]
}
}

Then the following two calls to the body method seem to function identically:

...body("lotto.winners.winnerId", hasItems(23, 54))

and

...body("lotto.winners.WINNERID", hasItems(23, 54))

This does indeed fail:

when().
get("/lotto").
then().
body("lotto.winners.WINNERID", hasItems(23, 54));
 java.lang.AssertionError: 1 expectation failed.
JSON path lotto.winners.WINNERID doesn't match.
Expected: (a collection containing <23> and a collection containing <54>)
  Actual: [null, null]


However, if you try to do something like ...body("lotto.WINNERS", notNullValue()) -- this will fail. 

Yes this also fails. Please upgrade to the lastest version of REST Assured!

Regards,
/Johan
Reply all
Reply to author
Forward
0 new messages