使用Skyscreamer比较两个json文件时如何忽略某些属性 [英] How to ignore certain attributes when comparing two json files using skyscreamer
本文介绍了使用Skyscreamer比较两个json文件时如何忽略某些属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用skyscreamer比较两个JSON文件时,我想排除某些JSON属性.
I want to exclude certain JSON attributes when comparing two JSON files using skyscreamer.
测试文件1:
{
"Name":"test1",
"addressList":[
{
"street":"123 fake street",
"postalcode":"33344"
},
{
"street":"99 street avn",
"postalcode":"23434"
},
{
"street":"900 street city",
"postalcode":"45100"
}
]
}
测试文件2:
{
"Name":"test1",
"addressList":[
{
"street":"123 fake street",
"postalcode":"33344"
},
{
"street":"88 abc street",
"postalcode":"23434"
},
{
"street":"900 street city",
"postalcode":"45100"
}
]
}
如何通过排除addressList.street属性来比较上述JSON文件?
how to compare above JSON files by excluding addressList.street attribute?
推荐答案
我们可以使用CustomComparator并根据需要编写自己的自定义比较器
we can use the CustomComparator and write an own custom comparator based on needs
org.skyscreamer.jsonassert.Customization
org.skyscreamer.jsonassert.comparator.CustomComparator
示例:
compareJSON(expected, actual, new CustomComparator(JSONCompareMode,new Customization(addressList.street,(o1, o2) -> true)))
这篇关于使用Skyscreamer比较两个json文件时如何忽略某些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文