我有一个http请求,其中我传递了另一个对象内的对象。例如:
DisciplinaDTO{
private Long id_disciplina;
private String st_nome;
private ArrayList<AlunoListDTO> ls_alunos;
}
AlunoListDTO{
private Long id_aluno;
private String st_nome_aluno;
}
当我尝试从我的前端传递一个关于这个物体的Json时。终端显示这个错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.tcc.secretaria.DTO.AlunoListDTO]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.tcc.secretaria.DTO.AlunoListDTO` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (PushbackInputStream); line: 1, column: 154] (through reference chain: com.tcc.secretaria.DTO.DisciplinaDTO["ls_alunos"]->java.util.ArrayList[0])] with root cause
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.tcc.secretaria.DTO.AlunoListDTO` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
我认为这是因为我在其他对象上有一个Object。但我怎么能通过这个呢?
我的构造函数:
public DisciplinaDTO(Long id_disciplina, String st_nome, ArrayList<AlunoListDTO> ls_alunos) {
this.id_disciplina = id_disciplina;
this.st_nome = st_nome;
this.ls_alunos = ls_alunos;
}