Example usage for com.mongodb.util JSON serialize

List of usage examples for com.mongodb.util JSON serialize

Introduction

In this page you can find the example usage for com.mongodb.util JSON serialize.

Prototype

public static String serialize(final Object object) 

Source Link

Document

Serializes an object into its JSON form.

This method delegates serialization to JSONSerializers.getLegacy

Usage

From source file:act.shared.helpers.XMLToImportantChemicals.java

License:Open Source License

private void printEntry(DBObject json) {
    Object ido = json.get(idTag);
    Object caso = json.get(chemTag);
    String id = ido instanceof String ? (String) ido : "";
    String cas = caso instanceof String ? (String) caso : "";
    String inchi = getInchi(json);
    if (inchi != null)
        System.out.format("%s\t%s\t%s\t%s\n", this.DBS, id, inchi, JSON.serialize(json));
    else//www  . j a v a  2  s.co m
        System.out.format("%s\t%s\t%s\t%s\n", this.DBS, id, cas, JSON.serialize(json));
}

From source file:act.shared.helpers.XMLToImportantChemicals.java

License:Open Source License

private void printUnwantedEntry(DBObject json) {
    System.err.format("%s\t%s\t%s\t%s\n", "UNKNOWN", "ID?", "CAS?", JSON.serialize(json));
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String getAll(String tableName) {
    if (tableName == null || tableName.equals("")) {
        return "501";
    }/*from  ww  w .  j a  v a2  s  . c  o  m*/
    String row = "";
    DBCollection table = db.getCollection(tableName);
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("status", "active");
    DBCursor cursor = table.find(searchQuery);
    if (cursor.size() > 0) {
        JSON json = new JSON();
        row = json.serialize(cursor);
        cursor.close();
        return row;
    } else {
        cursor.close();
        return null;
    }
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String getByKey(String tableName, String _id) {
    if (tableName == null || tableName.equals("") || _id == null || _id.equals("")) {
        return "501";
    }//from   w ww  .j  av a2 s .  co m
    String row = null;
    DBCursor cursor = null;
    DBCollection table = db.getCollection(tableName);
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(_id));
    cursor = table.find(searchQuery);
    if (cursor.size() > 0) {
        JSON json = new JSON();
        row = json.serialize(cursor);
        cursor.close();
        return row;
    } else {
        cursor.close();
        return null;
    }
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String getByCondition(String tableName, Map condition) {
    if (tableName == null || tableName.equals("") || condition == null || condition.equals("")) {
        return "501";
    }/*w  w  w  . j  av a2 s .  co m*/
    String row = "";
    DBCollection table = db.getCollection(tableName);
    BasicDBObject searchQuery = new BasicDBObject(condition);
    BasicDBObject andQuery = new BasicDBObject();
    andQuery.put("$and", searchQuery);
    DBCursor cursor = table.find(searchQuery);
    if (cursor.size() > 0) {
        JSON json = new JSON();
        row = json.serialize(cursor);
        cursor.close();
        return row;
    } else {
        cursor.close();
        return null;
    }
}

From source file:cc.acs.mongofs.gridfs.GridFSFile.java

License:Apache License

public String toString() {
    return JSON.serialize(this);
}

From source file:cfel.servlet.ServiceServlet.java

License:Open Source License

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    System.out.println(JSON.serialize(mDS.getCollectionNames()));
}

From source file:cfel.servlet.ServiceServlet.java

License:Open Source License

private void sendJSON(Object obj, HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json");
    response.addHeader("Access-Control-Allow-Origin", "*");
    if (obj instanceof WriteResult) {
        String error = ((WriteResult) obj).getError();
        if (error != null) {
            obj = error;//w ww.j av  a 2s. co  m
        } else {
            obj = "OK";
        }
    }
    OutputStream os = null;
    try {
        (os = response.getOutputStream()).write(JSON.serialize(obj).getBytes("UTF-8"));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (os != null) {
            os.close();
        }
    }
}

From source file:ch.bfh.uniboard.persistence.mongodb.PersistedPost.java

License:GNU General Public License

/**
 * Method allowing to retrieve a PersistedPost out of the DBObject returned by the database. If the passed DBObject
 * does not represent a PersistedPost, an empty PersistedPost is retuned
 *
 * @param doc the DBObject returned by the database
 * @return the corresponding persisted post
 *///  w ww.ja va2 s .  c o m
public static PersistedPost fromDBObject(DBObject doc) {
    PersistedPost pp = new PersistedPost();

    //TODO remove try catch when DB will be cleaned
    //this is only needed since some messages in MongoDB are not byte array
    //but string (historical reasons
    try {
        pp.message = Base64.decode((String) doc.get("message"));
    } catch (ClassCastException e) {
        pp.message = JSON.serialize(doc.get("message")).getBytes();
    }

    //fill alpha attributes
    Attributes alpha = new Attributes();
    DBObject alphaList = (DBObject) doc.get("alpha");
    for (String key : alphaList.keySet()) {
        //String key = dbObj.keySet().iterator().next();
        alpha.add(key, inflateType(alphaList.get(key)));
    }
    pp.alpha = alpha;

    //fill beta attributes
    Attributes beta = new Attributes();
    DBObject betaList = (DBObject) doc.get("beta");
    for (String key : betaList.keySet()) {
        //String key = dbObj.keySet().iterator().next();
        beta.add(key, inflateType(betaList.get(key)));
    }
    pp.beta = beta;

    return pp;
}

From source file:cn.vlabs.clb.server.storage.mongo.extend.MyGridFSFile.java

License:Apache License

@Override
public String toString() {
    return JSON.serialize(this);
}