86
rated 0 times
[
91]
[
5]
/ answers: 1 / hits: 11643
/ 10 Years ago, wed, may 28, 2014, 12:00:00
I want to remove attributes that have empty collections or null values using gson.
Aiperiodo periodo = periodoService();
//periodo comes from a service method with a lot of values
Gson gson = new Gson();
String json = gson.toJson(periodo);
I print json and I have this:
{idPeriodo:121,codigo:2014II,
activo:false,tipoPeriodo:1,
fechaInicioPreMatricula:may 1, 2014,
fechaFinPreMatricula:jul 1, 2014,
fechaInicioMatricula:jul 15, 2014,
fechaFinMatricula:ago 3, 2014,
fechaInicioClase:ago 9, 2014,
fechaFinClase:dic 14, 2014,
fechaActa:ene 15, 2015,
fechaUltModificacion:May 28, 2014 12:28:26 PM,
usuarioModificacion:1,aiAvisos:[],
aiAlumnoCarreraConvalidacionCursos:[],
aiAlumnoMatriculas:[],aiMallaCurriculars:[],
aiAlumnoCarreraEstados:[],aiAdmisionGrupos:[],
aiMatriculaCronogramaCabeceras:[],
aiAlumnoCarreraConvalidacions:[],
aiHorarioHorases:[],aiAsistencias:[],
aiAlumnoPreMatriculas:[],
aiAlumnoMatriculaCursoNotaDetalles:[],
aiOfertaAcademicas:[],aiTarifarios:[]}
For example for that json I don't want to have the collection aiAvisos, there is a way to delete this from the json.
I'm working with a lot of collections actually here I show one, I really need remove these from the json.
I need something like this:
{idPeriodo:121,codigo:2014II,
activo:false,tipoPeriodo:1,
fechaInicioPreMatricula:may 1, 2014,
fechaFinPreMatricula:jul 1, 2014,
fechaInicioMatricula:jul 15, 2014,
fechaFinMatricula:ago 3, 2014,
fechaInicioClase:ago 9, 2014,
fechaFinClase:dic 14, 2014,
fechaActa:ene 15, 2015,
fechaUltModificacion:May 28, 2014 12:28:26 PM,
usuarioModificacion:1}
I tried setting the collections to null, I check the documentation and there's no method there neither...
Please any suggestions.
Thanks a lot who read this!
More From » java