2016-04-29 42 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