简体   繁体   中英

Id with null value in return with mongoDB

@MongoObjectId annotation was added to insert as ObjectId in the database, but when I get all the data contained in this collection is the return to the null id. But the ids are and their values .
How do I get the id correctly?

My entity

import org.jongo.marshall.jackson.oid.MongoObjectId;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Instancia implements Serializable {

    @MongoObjectId
    String id;
    String instancia;
    String categoria;
    String dono;
    String data_criacao;
    String descricao;
    Boolean ativo;
    Map<String, Boolean> servicos;

    public String getId() {
        return this.id;
    }

    public Instancia setId(String id) {
        this.id = id;
        return this;
    }

    public String getInstancia() {
        return this.instancia;
    }

    public Instancia setInstancia(String instancia) {
        this.instancia = instancia;
        return this;
    }

    public String getCategoria() {
        return this.categoria;
    }

    public Instancia setCategoria(String categoria) {
        this.categoria = categoria;
        return this;
    }

    public String getDono() {
        return this.dono;
    }

    public Instancia setDono(String dono) {
        this.dono = dono;
        return this;
    }

    public String getData_criacao() {
        return this.data_criacao;
    }

    public Instancia setData_criacao(String data_criacao) {
        this.data_criacao = data_criacao;
        return this;
    }

    public String getDescricao() {
        return this.descricao;
    }

    public Instancia setDescricao(String descricao) {
        this.descricao = descricao;
        return this;
    }

    public Boolean getAtivo() {
        return this.ativo;
    }

    public Instancia setAtivo(Boolean ativo) {
        this.ativo = ativo;
        return this;
    }

    public Boolean isServicoEnabled(String servico) {
        Boolean b = this.servicos.get(servico);
        if(b == null){
            b = false;
        }
        return b;
    }

    public List<String> getServicosEnabled(){
        List<String> servicos = this.servicos.keySet().stream().filter((me) -> {
            Boolean b = this.servicos.get(me);
            if(b == null){
                b = false;
            }
            return b;
        }).collect(Collectors.toList());
        return servicos;
    }


}

How about trying to use Oid

Instancia instance = new Instancia();
instances.find(withOid(instance.id)).as(Instancia.class); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM