package leigh.eo.mongo;

import leigh.eo.EO;
import leigh.eo.EOJsonSerializer;
import leigh.mecha.json.JSONObject;
import org.bson.Document;

/**
 * This class provides wrapper functions for converting an {@link EO} to/from a
 * {@link org.bson.BsonDocument}.
 *
 * @author Alex Leigh
 */
public class EOBsonSerializer {
    public static Document eoToDoc(EO eo) {
        JSONObject jsonObj = EOJsonSerializer.toJson(eo);
        String json = jsonObj.toString();
        Document doc = org.bson.Document.parse(json);
        return doc;
    }

    public static EO docToEo(Document doc) {
        return EOJsonSerializer.toEo(new JSONObject(doc.toJson()));
    }
}
