List of usage examples for com.mongodb.util JSON serialize
public static String serialize(final Object object)
Serializes an object into its JSON form.
This method delegates serialization to JSONSerializers.getLegacy
From source file:com.strategicgains.docussandra.persistence.helper.DocumentPersistanceUtils.java
License:Apache License
/** * Marshals a Cassandra row into a Document object. * * @param row Row to marshal.// ww w .ja v a2 s . com * @return A document based on the provided row. */ public static Document marshalRow(Row row) { if (row == null) { return null; } Document d = new Document(); d.setUuid(row.getUUID(DocumentRepositoryImpl.Columns.ID)); ByteBuffer b = row.getBytes(DocumentRepositoryImpl.Columns.OBJECT); if (b != null && b.hasArray()) { byte[] result = new byte[b.remaining()]; b.get(result); BSONObject o = BSON.decode(result); d.object(JSON.serialize(o)); } d.setCreatedAt(row.getDate(DocumentRepositoryImpl.Columns.CREATED_AT)); d.setUpdatedAt(row.getDate(DocumentRepositoryImpl.Columns.UPDATED_AT)); return d; }
From source file:com.zjy.mongo.splitter.MultiCollectionSplitBuilder.java
License:Apache License
public String toJSON() { BasicDBList returnVal = new BasicDBList(); for (CollectionSplitterConf conf : collectionSplitters) { returnVal.add(new BasicDBObject(conf.toConfigMap())); }//from w w w . j a va2 s .c om return JSON.serialize(returnVal); }
From source file:com.zjy.mongo.util.MongoConfigUtil.java
License:Apache License
public static void setDBObject(final Configuration conf, final String key, final DBObject value) { conf.set(key, JSON.serialize(value)); }
From source file:com.zuehlke.sbdfx.dataaccess.mongo.MongoCitiesDao.java
private City toCity(final DBObject found) { if (found == null) { return null; }//from w w w.j av a 2s . c om final Gson gson = new Gson(); final String json = JSON.serialize(found); final City city = gson.fromJson(json, City.class); return city; }
From source file:data.repository.pragma.DataObjectController.java
License:Apache License
@RequestMapping("/DO/find/metadata") @ResponseBody// w ww .ja v a 2 s. c o m public MessageResponse DOfindMedata(@RequestParam(value = "ID", required = true) String ID) { // Connect to MongoDB and return DO metadata as response // return try { GridFSDBFile doc = Staging_repository.findDOByID(ID); DBObject doc_metadata = doc.getMetaData(); // Convert Json Node to message response type MessageResponse response = new MessageResponse(true, JSON.serialize(doc_metadata)); return response; } catch (Exception e) { // TODO Auto-generated catch block MessageResponse response = new MessageResponse(false, null); return response; } }
From source file:data.repository.pragma.PermanentRepoController.java
License:Apache License
@RequestMapping("/repo/find/metadata") @ResponseBody//from w ww . ja v a 2s . c o m public MessageResponse DOfindMedata(@RequestParam(value = "ID", required = true) String ID) { // Connect to MongoDB and return DO metadata as response // return try { GridFSDBFile doc = permanent_repository.findDOByID(ID); DBObject doc_metadata = doc.getMetaData(); // Convert DBObject to message response type MessageResponse response = new MessageResponse(true, JSON.serialize(doc_metadata)); return response; } catch (Exception e) { // TODO Auto-generated catch block MessageResponse response = new MessageResponse(false, null); return response; } }
From source file:de.ifgi.fmt.mongo.conv.JSONConverter.java
License:Open Source License
/** * //from w ww . j a va2 s. co m * @param c * @param o * @param i * @return * @throws MappingException */ @Override public Object decode(Class c, Object o, MappedField i) throws MappingException { if (o == null) return null; try { String s = JSON.serialize(o); return new JSONObject(s); } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:edu.purdue.cybercenter.dm.util.DatasetUtils.java
public static String serialize(Object object) { return JSON.serialize(object); }
From source file:es.bsc.mongoal.QueryGenerator.java
/** * Sends a query to the MongoDB database * @param queryString MongoAL query// www. j av a 2s. c om * @return An iterable collection of MongoDB DBobjects with the results of the query */ public Iterable<DBObject> query(String queryString) { MongoALLexer lexer = new MongoALLexer(new org.antlr.v4.runtime.ANTLRInputStream(queryString)); CommonTokenStream tokens = new CommonTokenStream(lexer); MongoALParser parser = new MongoALParser(tokens); Object[] ret = (Object[]) queryVisitor.visitQuery(parser.query()); System.out.println(JSON.serialize(ret[1])); DBCollection events = database.getCollection((String) ret[0]); if (ret[1] == null) { return events.find(); } else { return events.aggregate((List<DBObject>) ret[1]).results(); } }
From source file:essex.bigessexnew.OplogListener.java
private void performListenTask(DBCursor cur) { EssexDataHandler dh = new EssexDataHandler(Params.getProperty("essexHostPath")); Mongo mongo2 = new Mongo(Params.getProperty("host"), Integer.parseInt(Params.getProperty("port"))); DBCollection realCollection = mongo2.getDB(Params.getProperty("shardedDB")) .getCollection(Params.getProperty("shardedCollection")); Runnable task = () -> {// www . j av a2s .c o m System.out.println("\tWaiting for events"); while (cur.hasNext()) { DBObject obj = cur.next(); System.out.println(obj.toString()); JSONObject output = new JSONObject(JSON.serialize(obj)); String id = output.getJSONObject("o").getJSONObject("_id").getString("$oid"); String opType = output.getString("op"); String content = retrieveContent(realCollection, id); dh.handle(content, opType); } }; new Thread(task).start(); }