I have a web service hosted on Java in Netbeans (NO MAVEN) with several classes that are related to foreign keys. For example, I have a Notes class that has two foreign keys (idUsuari and idIncidencia). From the Postman, I do a GET with the method that comes by default when generating the service, which returns a List and shows it to me in Json format because that's how I have it in the get method:
Method:
GET
@Override
@Produces({MediaType.APPLICATION_JSON})
public List<Notes> findAll() {
return super.findAll();
}
And he returns me:
[
{
"dataNota": "2017-04-01",
"descripcio": "nota de la incidencia",
"id": 1,
"idIncidencia": { //objeto Incidencia
"dataFi": "2017-04-06",
"dataIncidencia": "2017-03-25",
"dataInici": "2017-04-06",
"descCurta": "Aixeta trencada",
"descLlarga": "La aixeta del lavabo situat a la dreta està bessant aigua continuament",
"id": 1,
"idEstat": {
"id": 2,
"nomEstat": "assignada"
},
"idLocalitzacio": {//objeto Localitzacio
"id": 12,
"nomLloc": "dpt. exportació"
},
"idPrioritat": {//objeto Prioritat
"id": 2,
"nomPrioritat": "normal"
},
"idUsuariObertura": { //objeto Usuari
"bloquejat": false,
"cognoms": "Olivera Cortes",
"contrasenya": "e10adc3949ba59abbe56e057f20f883e",
"correu": "[email protected]",
"id": 2,
"idTipus": { //objeto TipusUsuari
"id": 2,
"nomTipus": "gestor"
},
"idUsuari": "EulaliaOli2",
"mobil": "698899663",
"nom": "Calatina"
},
"idUsuariOperari": { //objeto Usuari
"bloquejat": false,
"cognoms": "Olivera Cortes",
"contrasenya": "e10adc3949ba59abbe56e057f20f883e",
"correu": "[email protected]",
"id": 3,
"idTipus": { //objeto TipusUsuari
"id": 2,
"nomTipus": "gestor"
},
"idUsuari": "EulaliaOli",
"mobil": "698899663",
"nom": "Eulalia"
}
},
"idUsuari": { //objeto Usuari
"bloquejat": false,
"cognoms": "Campmany",
"contrasenya": "0c924da91233daf35ad47a7745d10edf",
"correu": "[email protected]",
"id": 7,
"idTipus": { //objeto TipusUsuari
"id": 2,
"nomTipus": "gestor"
},
"idUsuari": "Joan",
"mobil": "",
"nom": "Joan"
},
"metodologia": "manual"
},
...mas registros con la misma estructura...
What I want is to convert this list of objects (which contains other objects and at the same time other objects) to a String in Json format. I've tried with Gson, JSONObject, Jackson and it does not return anything, the Postman is left standing as if thinking.
I do not know if the problem is that these libraries do not recognize the different levels within the hierarchy of objects or the EntityManager behind these restful methods.
Any suggestions?