Good afternoon, my question may be very simple for some, but I am learning and I cannot get a good result.
I have an API which requires obtaining a json object with the following structure:
{
"usuario": {
"ID_USUARIO": 0,
"CORREO": "maaridano12345@CORREO.com",
},
"persona": {
"ID_USUARIO": 0,
"NOMBRE_COMPLETO": "MaARIANO2 GARFEL",
"domicilios" : [{
"COLONIA" : "CaOLONIA23",
"CALLE" : "SaTREET",
}]
},
"asociado": {
"FOTO": "",
"ID_USUARIO": 0,
"NOMBRE_EMPRESA": "EMPRESAMARIANO2",
"tipoPagos" : [{
"ID_TIPO_PAGO" : 1
}],
"SERVICIOS" : [{
"ID_SERVICIO" : 2
}]
}
}
but, when I create my JSON object:
Registro = new mRegistro(userList, personList, asociadoList);
Gson gson = new Gson();
json = gson.toJson(Registro);
the structure that creates me is the following
{
"usuario": [{
"ID_USUARIO": 0,
"CORREO": "maaridano12345@CORREO.com",
}],
"persona": [{
"ID_USUARIO": 0,
"NOMBRE_COMPLETO": "MaARIANO2 GARFEL",
"domicilios" : [{
"COLONIA" : "CaOLONIA23",
"CALLE" : "SaTREET",
}]
}],
"asociado": [{
"FOTO": "",
"ID_USUARIO": 0,
"NOMBRE_EMPRESA": "EMPRESAMARIANO2",
"tipoPagos" : [{
"ID_TIPO_PAGO" : 1
}],
"SERVICIOS" : [{
"ID_SERVICIO" : 2
}]
}]
}
I want the same structure but in the User, Person and Associate parameters I do not want it to have the square bracket, I know that it is there because it is a list, it is like this because my class "mRegistro" contains the classes "usuario, persona and asociado"
Code to add Objects:
usuario = new User(0,emailInput,passwordInput,nameInput,false,false,true,false);
ArrayList<Adress> Domicilios = new ArrayList<Adress>();
domicilio = new Adress("MONARCAS","CALLETEST",34,12,83550,1,0,2);
Domicilios.add(domicilio);
persona = new Person(0, "MARIANO GARFEL","MARIANO","GARFEL","GARCIA", "9876347586","8575757575",
"GARFSONAL@GMAIL.COM","CORREO2@FDS.COM", Domicilios);
ArrayList<Services> Servicios = new ArrayList<Services>();
tipo_servicio = new Services(2);
Servicios.add(tipo_servicio);
ArrayList<PaymentType> TipoPago = new ArrayList<PaymentType>();
tipo_pago = new PaymentType(2);
TipoPago.add(tipo_pago);
asociado = new Associate("",0,"LaEmpresaChida",0,0,"La mejor empresa",2, Servicios, TipoPago );
ArrayList<mRegistro> RegistroAsociado = new ArrayList<mRegistro>();
ArrayList<Associate> asociadoList = new ArrayList<Associate>();
asociadoList.add(asociado);
ArrayList<Person> personList = new ArrayList<Person>();
personList.add(persona);
ArrayList<User> userList = new ArrayList<User>();
userList.add(usuario);
Registro = new mRegistro(userList, personList, asociadoList);