Skip to content
Java Object Mapper for Mongodb
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Java Object Mapper for MongoDB

#Based in:

  • Java Driver for MongoDB
  • GSon

Contacts: Aristides Villareal Bravo

It works similar to JPA, visit Wiki for Documentation


1.Add to pom.xml








2. Create beans



public class Paises extends GenericBeans {



private String siglas;


private String pais;


private String logo;

public Document toDocument(Paises paises) {
    Document doc = new Document();
    try {
        doc = Document.parse(getGson().toJson(paises));
    } catch (Exception e) {
        System.out.println("toDocument() " + e.getLocalizedMessage());
    return doc;

public Paises toPojo(Document doc) {
    Paises paises = new Paises();
    try {
        paises = (Paises) fromJsontoPojo(doc.toJson(), new Paises().getClass());
    } catch (Exception e) {
        System.out.println("toPojo() " + e.getLocalizedMessage());
    return paises;


public String toString() {

    return "Paises{" + "siglas=" + siglas + ", pais=" + pais + '}';


A. For Java Standar Edition

Create Facade

public class PaisesFacade extends AbstractFacade{

public PaisesFacade( ){
    super(Paises.class, "mydatabase", "paises");

protected MongoClient getMongoClient() {
     MongoClient mongoClient = new MongoClient();
     return mongoClient;


** Example**

PaisesFacade paisesFacade =new PaisesFacade();

    Paises paises = new Paises();
    //save document;
    //list all document
    List<Paises> list = paisesFacade.findAll(); -> {

B. For Java Enterprise Edition

Create MongoClientProvider



public class MongoClientProvider {

private MongoClient mongoClient = null;
public MongoClient getMongoClient(){	
	return mongoClient;

public void init() {
        try {		
            mongoClient = new MongoClient();
        } catch (Exception e) {
            JSFUtil.addErrorMessage("init() "+e.getLocalizedMessage());


Create Facade


public class PaisesFacade extends AbstractFacade {


 MongoClientProvider mongoClientProvider;


protected MongoClient getMongoClient() {

     return mongoClientProvider.getMongoClient();


public PaisesFacade() {      

     super(Paises.class, "mydatabase", "paises");






public class PaisesController implements Serializable {


PaisesFacade paisesFacade;

public Boolean save(Paises paises){



public List getPaises(){

  return paisesFacade.findAll();


You can’t perform that action at this time.