При попытке отсортировать список типа WlMatch, как показано в приведенном ниже коде, я вижу исключение:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.Comparable
Я пытался использовать сопоставимую сортировку и сортировку компаратора, но привел к той же ошибке.Может кто-то с большим опытом руководства, где я буду не так.
ReadContext readContext = JsonPath.parse(responseJson);
List<WlMatch> wlMatchs = readContext.read("$.response.watchList.searchResult.records.resultRecord[0].watchlist.matches.wlmatch");
if (wlMatchs != null) {
// wlMatchs.sort(Comparator.comparingInt(WlMatch::id));
wlMatchs.sort(new Comparator<WlMatch>() {
@Override
public int compare(WlMatch w1, WlMatch w2) {
if (w1.getId() == w2.getId()) {
return 0;
}
return w1.getId() - w2.getId();
}
});
В случае, если вы хотите увидеть, что в списке.Значение wlMatchs в режиме отладки равно
[
{
addresses=address,
bestName=null,
reasonListed=null,
countryDetails=country,
matchReAlert=null,
phones=null,
resultDate=0,
acceptListID=acceptlist,
bestNameScore=0,
error=null,
bestCountry=null,
trueMatch=null,
doBs=null,
file={
published=3123123213,
build=111,
name=file1,
id=456,
type=txt,
custom=true
},
entityDetails={
akAs=null,
addresses={
entityAddress=[
{
stateProvinceDistrict=null,
country=India,
comments=null,
city=Hyderabad,
postalCode=500001,
street1=null,
id=0,
street2=null,
type=null
}
]
},
dateListed=null,
comments=null,
gender=MALE,
listReferenceNumber=null,
reasonListed=reason,
entityType=IND,
additionalInfo={
entityAdditionalInfo=[
{
comments=null,
id=0,
type=DOB,
value=12-12-1989
}
]
},
name=null,
iDs=null,
phones=null
},
entityName=In,
falsePositive=null,
gatewayOFACScreeningIndicatorMatch=null,
previousResultID=null,
conflicts=null,
iDs=null,
entityScore=0,
id=456,
addedToAcceptList=true,
matchXML=null,
secondaryOFACScreeningIndicatorMatch=null,
entityUniqueID=null,
autoFalsePositive=null,
bestCountryScore=null,
citizenships=null,
checkSum=0,
addressName=true,
ofacInfo=null,
bestAddressIsPartial=null,
bestCountryType=null
},
{
addresses=address,
bestName=null,
reasonListed=null,
countryDetails=country,
matchReAlert=null,
phones=null,
resultDate=0,
acceptListID=acceptlist,
bestNameScore=0,
error=null,
bestCountry=null,
trueMatch=null,
doBs=null,
file={
published=3123123213,
build=111,
name=file1,
id=789,
type=txt,
custom=true
},
entityDetails={
akAs=null,
addresses={
entityAddress=[
{
stateProvinceDistrict=null,
country=India,
comments=null,
city=Hyderabad,
postalCode=500001,
street1=null,
id=0,
street2=null,
type=null
}
]
},
dateListed=null,
comments=null,
gender=MALE,
listReferenceNumber=null,
reasonListed=reason,
entityType=IND,
additionalInfo={
entityAdditionalInfo=[
{
comments=null,
id=0,
type=DOB,
value=12-12-1989
}
]
},
name=null,
iDs=null,
phones=null
},
entityName=In,
falsePositive=null,
gatewayOFACScreeningIndicatorMatch=null,
previousResultID=null,
conflicts=null,
iDs=null,
entityScore=0,
id=789,
addedToAcceptList=true,
matchXML=null,
secondaryOFACScreeningIndicatorMatch=null,
entityUniqueID=null,
autoFalsePositive=null,
bestCountryScore=null,
citizenships=null,
checkSum=0,
addressName=true,
ofacInfo=null,
bestAddressIsPartial=null,
bestCountryType=null
},
{
addresses=address,
bestName=null,
reasonListed=null,
countryDetails=country,
matchReAlert=null,
phones=null,
resultDate=0,
acceptListID=acceptlist,
bestNameScore=0,
error=null,
bestCountry=null,
trueMatch=null,
doBs=null,
file={
published=3123123213,
build=111,
name=file1,
id=123,
type=txt,
custom=true
},
entityDetails={
akAs=null,
addresses={
entityAddress=[
{
stateProvinceDistrict=null,
country=India,
comments=null,
city=Hyderabad,
postalCode=500001,
street1=null,
id=0,
street2=null,
type=null
}
]
},
dateListed=null,
comments=null,
gender=MALE,
listReferenceNumber=null,
reasonListed=reason,
entityType=IND,
additionalInfo={
entityAdditionalInfo=[
{
comments=null,
id=0,
type=DOB,
value=12-12-1989
}
]
},
name=null,
iDs=null,
phones=null
},
entityName=In,
falsePositive=null,
gatewayOFACScreeningIndicatorMatch=null,
previousResultID=null,
conflicts=null,
iDs=null,
entityScore=0,
id=123,
addedToAcceptList=true,
matchXML=null,
secondaryOFACScreeningIndicatorMatch=null,
entityUniqueID=null,
autoFalsePositive=null,
bestCountryScore=null,
citizenships=null,
checkSum=0,
addressName=true,
ofacInfo=null,
bestAddressIsPartial=null,
bestCountryType=null
}
]