2016-04-29 43 views
0

我有时需要在价值观与空解析JSON这样的:JSONPath无法找到空键的值

{"someKey" : null}

,并验证someKey值为空,但似乎不可能:

所有其他

jsonPath被转换成字符串像这样:

{"someKey" : 2} 
.check(jsonPath("$.someKey").is("2")) //pass 

但空:

{"someKey" : null} 
.check(jsonPath("$.someKey").is("null")) 
//jsonPath($.extMediaThumbnailId).find(0).is(null), but actually found nothing 

.is(null)检查返回空指针异常

也许这是一个错误有没有一种方法来检查JSON值为null与jsonPath?

回答

3

目前仅当使用ofType[Any]明确设置预期类型为Any时才可能。但是您使用的是默认值,即String

我们将在即将到来的2.2.1中支持所有类型,请参阅issue here