我正在尝试根据使用 JSON 路径 REST-assured 的条件获取值列表。
以下是我的 JSON 响应,我想获取 credentialId 的值,其中 credentialType”是“禁止用户名”,我尝试了下面的代码,但是它为我返回 null 值。请帮助我正确的 JSONpath 以获取所需的价值观。
List<Object> object1 = response1.jsonPath().getList("credentials.findAll { it.credentialType=='Ban User Name' }");
[
{
"addresses": [
],
"dateOfBirth": null,
"credentials": [
{
"credentialId": "mregasapgreene",
"credentialType": "Ban User Name",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "MGREENE",
"credentialType": "Ban ID",
"effectiveEndDate": null,
"effectiveStartDate": null
}
],
"dateDeceased": null,
"emails": [
],
"ethnicity": null,
"guid": "3b020aed-1c69-469c-889d-301e8abce78c",
"maritalStatus": null,
"metadata": {
"dataOrigin": "GRAILS"
},
"names": [
{
"firstName": "Mallory",
"lastName": "(Reg as AP) Greene",
"middleName": "A",
"nameType": "Primary",
"pedigree": null,
"preferredName": null,
"lastNamePrefix": null,
"title": null
}
],
"phones": [
],
"races": [
],
"roles": [
{
"effectiveEndDate": null,
"effectiveStartDate": null,
"role": "Student"
}
],
"gender": null
},
{
"addresses": [
{
"addressType": "Mailing",
"city": "Seattle",
"country": null,
"county": null,
"region": "WA",
"streetAddress1": "123 Sesame Street",
"streetAddress2": null,
"streetAddress3": null,
"postalCode": "98199"
},
{
"addressType": "Home",
"city": "Malvern",
"country": {
"value": "United States of America",
"code": "US"
},
"county": null,
"region": "PA",
"streetAddress1": "412 Two Street",
"streetAddress2": null,
"streetAddress3": null,
"postalCode": "19355"
}
],
"dateOfBirth": null,
"credentials": [
{
"credentialId": "937",
"credentialType": "Ban Sourced ID",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "s11",
"credentialType": "Ban User Name",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "025EB9EF4420F0D0E05018958B283255",
"credentialType": "Ban UDC ID",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "A00000718",
"credentialType": "Ban ID",
"effectiveEndDate": null,
"effectiveStartDate": null
}
],
"dateDeceased": null,
"emails": [
],
"ethnicity": null,
"guid": "3f86c5e3-08b8-431b-bdc5-3ee250847976",
"maritalStatus": null,
"metadata": {
"dataOrigin": null
},
"names": [
{
"firstName": "Student",
"lastName": "101",
"middleName": null,
"nameType": "Primary",
"pedigree": null,
"preferredName": null,
"lastNamePrefix": null,
"title": null
}
],
"phones": [
{
"phoneExtension": null,
"phoneNumber": "+1 12",
"phoneType": "Home"
}
],
"races": [
],
"roles": [
{
"effectiveEndDate": null,
"effectiveStartDate": null,
"role": "Student"
}
],
"gender": null
},
{
"addresses": [
{
"addressType": "Mailing",
"city": "Seattle",
"country": null,
"county": null,
"region": "WA",
"streetAddress1": "123 Sesame Street",
"streetAddress2": null,
"streetAddress3": null,
"postalCode": "98199"
}
],
"dateOfBirth": null,
"credentials": [
{
"credentialId": "938",
"credentialType": "Ban Sourced ID",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "s12",
"credentialType": "Ban User Name",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "025EB9EF5535F0D0E05018958B283255",
"credentialType": "Ban UDC ID",
"effectiveEndDate": null,
"effectiveStartDate": null
},
{
"credentialId": "A00000719",
"credentialType": "Ban ID",
"effectiveEndDate": null,
"effectiveStartDate": null
}
],
"dateDeceased": null,
"emails": [
{
"emailAddress": "ilpstudent102@test.eln.com",
"emailType": "Personal",
"guid": "2a7d3ba4-9ec6-49b3-a3f8-a9e757f756a4"
},
{
"emailAddress": "ilpstudent102@test.eln.com",
"emailType": "Preferred",
"guid": "2a7d3ba4-9ec6-49b3-a3f8-a9e757f756a4"
}
],
"ethnicity": null,
"guid": "06c93bce-a380-4ff4-83a4-3a92e7cb18db",
"maritalStatus": null,
"metadata": {
"dataOrigin": null
},
"names": [
{
"firstName": "Student",
"lastName": "102",
"middleName": null,
"nameType": "Primary",
"pedigree": null,
"preferredName": null,
"lastNamePrefix": null,
"title": null
}
],
"phones": [
],
"races": [
],
"roles": [
{
"effectiveEndDate": null,
"effectiveStartDate": null,
"role": "Student"
}
],
"gender": null
}
]