问题
I'm creating a REST web service with Spring, but I'm getting a internal server error and don't understand why. I have a List of DoenteIdentidade's, this is the structure of the DoenteIdentidade
{
"id": 1,
"nome": "Highway Ergonomic",
"dataNasc": "2020-01-10",
"altura": 31098,
"morada": "moratorium pixel withdrawal",
"codPost": "Mississippi embrace Developer",
"freguesia": "synthesize Idaho compress",
"nif": 49379,
"medFam": "Poland",
"sexo": "Masculino",
"telef": 3142,
"telef2": 89576,
"docId": 63641,
"nBenef": 47537,
"nUtente": 31435,
"numProcHosp": 56327,
"doente": {
"id": 1,
"situacao": "StatusDP",
"horarioDoentes": null,
"doenteDiagnosticoSocials": null,
"doenteRegistosIntervencoes": null,
"doenteHistMovimentos": null,
"doenteContactosOutros": null,
"turnos": {
"id": 1,
"nome": "Metal"
}
},
"subsistemas": {
"id": 3,
"gidNome": "Small",
"gidCode": 14001,
"subSisGrupo": null
},
"centroSaude": null,
"hospRef": null,
"pais": null,
"aces": null
}
As you can see there is a object inside called Doente, what I'm trying to do is extract all the Doente objects contained inside all the DoenteIdentidade of this list to a List of Doente's.
Here is a snippet of the code I wrote for this goal, for some reason I'm getting a internal server error when I try to add to the List of Doente's.
else if(situacao == null && subSistema != null && t == null){
List<DoenteIdentidade> doenteIdentidades = doenteIdentidadeRepository.findAllBySubsistemasId(subSistema);
List<Doente> doentes2=null;
for (DoenteIdentidade doenteIdentidade: doenteIdentidades) {
doentes2.add(doenteIdentidade.getDoente());
}
return doentes2;
}
Any help is very welcomed.
回答1:
doentes2 is null when you are adding your doente. Try instead:
List<Doente> doentes2 = new ArrayList<>();
来源:https://stackoverflow.com/questions/59769786/why-am-i-getting-an-internal-server-error