'JSON is returning a list type object when it has 1 position as object and not as a list

I have a list of objects instantiated in a return class in a service's response. But when this list has 1 position, it is returning as an object and not as a list. can anybody help me?

@XmlRootElement(name = "exame")
public class ExameVO implements Serializable {

    private static final long serialVersionUID = -5840337332057658386L;

    private long id;
    
    @NotNull
    private String cpf;
    
    @NotNull
    private String dataNascimento;
    
    @NotNull
    private int tipoExame;
    
    @NotNull
    private String excluido;

    private List<ExameArquivoVO> resultadoExameArquivos;
    
    private String observacao;
    
    private String dataInclusao;

    public ExameVO() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public String getDataNascimento() {
        return dataNascimento;
    }

    public void setDataNascimento(String dataNascimento) {
        this.dataNascimento = dataNascimento;
    }

    public int getTipoExame() {
        return tipoExame;
    }

    public void setTipoExame(int tipoExame) {
        this.tipoExame = tipoExame;
    }

    public String getObservacao() {
        return observacao;
    }

    public void setObservacao(String observacao) {
        this.observacao = observacao;
    }

    public String getExcluido() {
        return excluido;
    }

    public void setExcluido(String excluido) {
        this.excluido = excluido;
    }

    public List<ExameArquivoVO> getResultadoExameArquivos() {
        return resultadoExameArquivos;
    }

    public void setResultadoExameArquivos(List<ExameArquivoVO> resultadoExameArquivos) {
        this.resultadoExameArquivos = resultadoExameArquivos;
    }

    public String getDataInclusao() {
        return dataInclusao;
    }

    public void setDataInclusao(String dataInclusao) {
        this.dataInclusao = dataInclusao;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    @Override
    public String toString() {
        return "ResultadoExameVO [id=" + id + ", cpf=" + cpf + ", dataNascimento=" + dataNascimento + ", tipoExame="
                + tipoExame + ", observacao=" + observacao + ", excluido=" + excluido + ", dataInclusao=" + dataInclusao
                + ", resultadoExameArquivos=" + resultadoExameArquivos + "]";
    }
    
}

@Override
    public List<ExameVO> listarExames(String cpf, String dtNascimento, Long tipoExame) throws WebServiceException {
        List<ExameVO> examesVO = new ArrayList<ExameVO>();

        try {
            examesVO = exameDAO.listarExames(cpf, dtNascimento, tipoExame);

            if(!examesVO.isEmpty()) {
                for(ExameVO exameVO : examesVO) {
                    exameVO.setResultadoExameArquivos(new ArrayList<ExameArquivoVO>());
                    exameVO.getResultadoExameArquivos().addAll(exameDAO.listarExameArquivos(exameVO.getId()));
                }
            }
            
            return examesVO;
        } catch (Exception e) {
            throw new WebServiceException(e);
        }
    }

Response to postman: Notice that there is 1 object that has 2 objects inside the file list and another object that has 1 and it returns as an object and not as a list with 1 object.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source