I'm using MockMvc to test an API which returns JSON content, and that JSON may contain a field called shares as an empty array, or may not be existed at all (I mean shares field).
JSON sample:
{
"id":1234,
.....
"shares":[]
}
//or
{
"id":1234,
....
}
How can I assert that this field is either empty or not existed
like:
mvc.perform(
post("....url.......")
.andExpect(status().is(200))
// I need one of the following to be true, but this code will assert both of them, so it will fail
.andExpect(jsonPath("$.shares").isEmpty())
.andExpect(jsonPath("$.shares").doesNotExist())