1

I have this very ugly POST request mapped on my controller

@PostMapping("/save")
public ResponseEntity<Cliente> save(@RequestBody ClienteSaveBody json) {
    Cliente persona = json.getCliente();
    Ubicacion location = json.getUbicacion();
    String nSector = json.getSector();
    Sector sector = sectorRepo.findById(nSector).orElseThrow(() -> new EntityNotFoundException("sector no encontrado para este id:: " + nSector));
    
    location.setSector(sector);
    location.setCliente(persona);
    persona.setUbicacion(location);
    ubicacionRepo.save(location);
    Cliente obj = clienteRepo.save(persona);
    return new ResponseEntity<Cliente>(obj, HttpStatus.OK);
}

and when I use this mapped request the console throws me an infinitely long warning.

When I do a GET this is the response:

{
   "nombreCompleto":"John Harold",
   "telefono":"111-111-1111",
   "email":"JH@gmail.com",
   "celular":"222-222-2222",
   "cedula":"22222222222",
   "sexo":"F",
   "fecha_Nacimiento":"2021-04-13T00:00:00.000+00:00",
   "ubicacion":{
      "calle":"Pepin",
      "casa":"2",
      "sector":{
         "nombreSector":"Cambelen",
         "nombreMunicipio":{
            "nombreMunicipio":"Puerto Plata",
            "nombreProvincia":{
               "nombreProvincia":"Puerto Plata"
            }
         }
      },
      "cliente":{
         "nombreCompleto":"John Harold",
         "telefono":"111-111-1111",
         "email":"JH@gmail.com",
         "celular":"222-222-2222",
         "cedula":"22222222222",
         "sexo":"F",
         "fecha_Nacimiento":"2021-04-13T00:00:00.000+00:00",
         "ubicacion":{
            "calle":"Pepin",
            "casa":"2",
            "sector":{
               "nombreSector":"Cambelen",
               "nombreMunicipio":{
                  "nombreMunicipio":"Puerto Plata",
                  "nombreProvincia":{
                     "nombreProvincia":"Puerto Plata"
                  }
               }
            },
            "cliente":{
               "nombreCompleto":"John Harold",
               "telefono":"111-111-1111",
               "email":"JH@gmail.com",
               "celular":"222-222-2222",
               "cedula":"22222222222",
               "sexo":"F",
               "fecha_Nacimiento":"2021-04-13T00:00:00.000+00:00",
               "ubicacion":{
                  "calle":"Pepin",
                  "casa":"2",
                  "sector":{
                     "nombreSector":"Cambelen",
                     "nombreMunicipio":{
                        "nombreMunicipio":"Puerto Plata",
                        "nombreProvincia":{
                           "nombreProvincia":"Puerto Plata"
                        }
                     }
                  },
                  "cliente":{
                     "nombreCompleto":"John Harold",
                     "telefono":"111-111-1111",
                     "email":"JH@gmail.com",
                     "celular":"222-222-2222",
                     "cedula":"22222222222",
                     "sexo":"F",
                     "fecha_Nacimiento":"2021-04-13T00:00:00.000+00:00",
                     "ubicacion":{
                        "calle":"Pepin",
                        "casa":"2",
                        "sector":{
                           "nombreSector":"Cambelen",
                           "nombreMunicipio":{
                              "nombreMunicipio":"Puerto Plata",
                              "nombreProvincia":{
                                 "nombreProvincia":"Puerto Plata"
                              }
                           }
                        },
                        "cliente":{
                           "nombreCompleto":"John Harold",
                           "telefono":"111-111-1111",
                           "email":"JH@gmail.com",
                           "celular":"222-222-2222",
                           "cedula":"22222222222"
Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89

1 Answers1

2

You can use @JsonIgnore above your mapping in your model.

@JsonIgnore
@OneToMany(mappedBy = "table_name",
            cascade = {CascadeType.REMOVE})
kameshsr
  • 327
  • 3
  • 13