2

Trabajo con springboot creando microservicios. Tengo mi código sin ningún error, compilo y no marca ningún error; subo mi .war a WebLogic y despliega, pero al momento de checar el microservicio en postman me marca el error

"status":500,"error":"Internal Server Error","path":"

Tal vez mi código no esté bien estructurado y ese sea el motivo. Adjunto mis clases de mi proyecto.

Controller

@RestController
@RequestMapping("/api")
public class EstatusController {
@Autowired
private IEstatusServices estatusServicesImpl;
@GetMapping(path = "/estatus")
public ResponseEntity<?> findAll() {
    Map<String, Object> response = new HashMap<>();
    List<EstatusDto> listCat = null;

    try {
        listCat = estatusServicesImpl.findAll();

    } catch (Exception e) {

        response.put("mensaje",ConstantesUtil.MESSAGE_ERROR_CONSULTA);
        response.put("error", e.getMessage().concat(": ").concat(e.getMessage()));
        return new ResponseEntity<Map<String, Object>>(response, 
 HttpStatus.INTERNAL_SERVER_ERROR);
    }
    if (listCat == null) {
        response.put("mensaje", "");
        return new ResponseEntity<Map<String, Object>>(response, HttpStatus.NOT_FOUND);
    }

    return new ResponseEntity<List<EstatusDto>>(listCat, HttpStatus.OK);
}

@GetMapping(path = "estatus/activo/{IdActivo}")
public ResponseEntity<?> findByIdActivo(@PathVariable("idActivo") int idActivo) {
    Map<String, Object> response = new HashMap<>();
    List<EstatusDto> listCat = null;

    try {
        listCat = estatusServicesImpl.findbyidActivo(idActivo);

    } catch (Exception e) {
        response.put("mensaje",ConstantesUtil.MESSAGE_ERROR_CONSULTA);
        response.put("error", e.getMessage().concat(": ").concat(e.getMessage()));
        return new ResponseEntity<Map<String, Object>>(response, HttpStatus.INTERNAL_SERVER_ERROR);
    }
    if (listCat == null) {
        response.put("mensaje", "");
        return new ResponseEntity<Map<String, Object>>(response, HttpStatus.NOT_FOUND);
    }

    return new ResponseEntity<List<EstatusDto>>(listCat, HttpStatus.OK);
}
}

DAO

public interface IActivoDao  extends CrudRepository<ActivoModel,String> {
List<EstatusDto> findByidActivo(int idActivo);
 }

DTO

@AllArgsConstructor
@NoArgsConstructor
public class EstatusDto implements Serializable {
/**
* 
*/
private static final long serialVersionUID = 1L;
@Setter
@Getter
private int idActivo;
@Setter
@Getter
private String activo;

}

model

 @Entity
@Table (name="ACTIVO")
public class ActivoModel implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
@Id
@Column (name="IDACTIVO")
@Setter@Getter
private int idActivo;
@Column (name="ACTIVO")
@Setter@Getter
private String activo;
@Column (name="FECHAREGISTRO")
@Setter@Getter
private Date fechaRegistro;
@Column (name="IDUSUARIOREGISTRO")
@Setter@Getter
private int idUsuarioRegistro;
}

mi service

 @Service
 public interface IEstatusServices {
    List<EstatusDto> findAll();
List<EstatusDto> findbyidActivo(int idActivo);
}

mi serviceimplement

  @Service("estatusServicesImpl")
  public class EstatusServicesImpl implements IEstatusServices {
  @Autowired
  private IActivoDao activoDaoImpl;

@Autowired
private Mapper dozerMapper;

@Override
public List<EstatusDto> findAll() {
    List<EstatusDto> list = null;

    try {
        System.out.println("ingres a sevicicio estatus");
        List<ActivoModel> list2 = (List<ActivoModel>) activoDaoImpl.findAll();

        System.out.println("dro" + dozerMapper);
        if (list2 != null && list2.size() > 0) {
            System.out.println("ingreso if");

            list = list2.stream().map((catalogo) -> {
                return dozerMapper.map(catalogo, EstatusDto.class);
            }).collect(Collectors.toList());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return list;
}

@Override
public List<EstatusDto> findbyidActivo(int idActivo) {
    
    List<EstatusDto> listDto = null;
    List<EstatusDto> listModel = activoDaoImpl.findByidActivo( idActivo);
    if (listModel != null) {
        listDto = listModel.stream().map((catalogo) -> {
            return dozerMapper.map(catalogo, EstatusDto.class);
        }).collect(Collectors.toList());

    }

    return listDto;
}
}

Este el error me manda cuando lo ejecuto con potsman en la consola de eclipse

> Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class mx.gob.issfam.dti.api.dto.EstatusDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])
    at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.12.3.jar:2.12.3]

1 respuesta 1

1

Intente agregar la siguiente línea a su archivo application.properties:

spring.jackson.serialization.fail-on-empty-beans=false

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.