Estou com este erro.
11:22:15,611 WARN [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-2) Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of br.eti.netsoft.nfse.enuns.TipoErroAlertaEnum, problem: { at [Source: java.io.PushbackInputStream@20db40c9; line: 2, column: 3] (through reference chain: br.eti.netsoft.nfse.model.nfse.ErroAlertaEntity["tipoErroAlerta"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of br.eti.netsoft.nfse.enuns.TipoErroAlertaEnum, problem: { at [Source: java.io.PushbackInputStream@20db40c9; line: 2, column: 3] (through reference chain: br.eti.netsoft.nfse.model.nfse.ErroAlertaEntity["tipoErroAlerta"])
JAVA
Carregamento do ENUM para o Angular:
@GetMapping(value = "/todosTiposErroAlerta", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public RetornoJackson todosTiposErroAlertaEnum() { retorno = new RetornoJackson(); Set<TipoErroAlertaEnum> listaEnuns = new LinkedHashSet<>(); for (TipoErroAlertaEnum tipoErroAlertaEnum : tiposErrosAlertasEnum()) { listaEnuns.add(tipoErroAlertaEnum); } retorno.setLista(listaEnuns); return retorno; }
Mapeamento do campo:
@Column(name = "ST_TIPO_ERRO_ALERTA", length = 10, nullable = false) @Enumerated(EnumType.STRING) public TipoErroAlertaEnum getTipoErroAlerta() { return tipoErroAlerta; }
Angular - busca no typescript.
private buscarTodosTipoErroAlerta(){ this.erroAlertaService.buscarTodosTipoErroAlerta().subscribe( (data :any) => { this.tiposErrosAlertas = data.lista; }, err => { } ); }
PrimeNG:
<div class="ui-g-12 ui-md-4"> <div class="ui-g-4"> <h4 for="tipoErroAlerta">Tipo de erro / alerta</h4> <p-dropdown [options]="tiposErrosAlertas" placeholder="Selecione um..." optionLabel="tiposErrosAlertas" [showClear]="true" id="tipoErroAlerta" name="tipoErroAlerta" pTooltip="Selecione o tipo de erro / alerta" tooltipPosition="right" [(ngModel)]="erroAlerta.tipoErroAlerta"></p-dropdown> </div> </div>
Como faço para ajustar, isto é, o JAVA aceitar o ENUM, sem ter que criar uma DTO ?