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.github.mongo.labs.api.TalksService.java
License:Apache License
@GET @Path("/") @ApiOperation(value = "Retourne tous les talks") public String all() { BasicDBObject query = new BasicDBObject(); BasicDBObject projection = new BasicDBObject(); projection.put("_id", 1); projection.put("title", 1); projection.put("summary", 1); projection.put("speakers", 1); return JSON.serialize(dbCollection.find(query, projection)); }
From source file:com.github.mongo.labs.api.TalksService.java
License:Apache License
@GET @Path("/{id}") @ApiOperation(value = "Retrouve un talk par son identifiant (ex: XWC-772)", notes = "le service retourne un code 404 si non trouv", response = Talk.class) public String get(@PathParam("id") String id) { BasicDBObject query = new BasicDBObject("_id", id); return JSON.serialize(dbCollection.findOne(query)); }
From source file:com.jaeksoft.searchlib.crawler.database.DatabaseCrawlMongoDbThread.java
License:Open Source License
final private void runner_update(FindIterable<Document> iterable) throws SearchLibException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, ParseException, SyntaxError, URISyntaxException, InterruptedException { final int limit = databaseCrawl.getBufferSize(); iterable.batchSize(limit);//from w w w . j a v a2s.co m DatabaseFieldMap databaseFieldMap = databaseCrawl.getFieldMap(); List<IndexDocument> indexDocumentList = new ArrayList<IndexDocument>(0); LanguageEnum lang = databaseCrawl.getLang(); FieldMapContext fieldMapContext = new FieldMapContext(client, lang); String uniqueField = client.getSchema().getUniqueField(); MongoCursor<Document> cursor = iterable.iterator(); while (cursor.hasNext() && !isAborted()) { String json = JSON.serialize(cursor.next()); Object document = Configuration.defaultConfiguration().jsonProvider().parse(json); IndexDocument indexDocument = new IndexDocument(lang); databaseFieldMap.mapJson(fieldMapContext, document, indexDocument); if (uniqueField != null && !indexDocument.hasContent(uniqueField)) { rwl.w.lock(); try { ignoredDocumentCount++; } finally { rwl.w.unlock(); } continue; } indexDocumentList.add(indexDocument); rwl.w.lock(); try { pendingIndexDocumentCount++; } finally { rwl.w.unlock(); } if (index(indexDocumentList, limit)) setStatus(CrawlStatus.CRAWL); } index(indexDocumentList, 0); }
From source file:com.kurento.kmf.repository.internal.repoimpl.filesystem.ItemsMetadata.java
License:Open Source License
public void save() { try {//from w ww .j ava 2 s.c o m if (!itemsMetadataFile.exists()) { itemsMetadataFile.getParentFile().mkdirs(); itemsMetadataFile.createNewFile(); } try (PrintWriter writer = new PrintWriter(itemsMetadataFile)) { String content = JSON.serialize(itemsMetadata); writer.print(content); } } catch (IOException e) { log.error("Exception writing metadata file", e); } }
From source file:com.machinelinking.storage.mongodb.MongoDocument.java
License:Apache License
@Override public String toJSON() { return JSON.serialize(getContent()); }
From source file:com.mingo.convert.DefaultConverter.java
License:Apache License
/** * {@inheritDoc}/*from ww w. ja v a2 s .c om*/ */ @Override public T convert(Class<T> type, DBObject source) { T result; source = getFirstElement(source); String json = JSON.serialize(source); try { result = objectMapper.readValue(json, type); } catch (IOException e) { LOGGER.error(ExceptionUtils.getMessage(e)); throw new ConversionException(e); } return result; }
From source file:com.mingo.query.aggregation.PipelineBuilder.java
License:Apache License
/** * Serialize basicDBList to json.// w ww . ja va 2s .c o m * * @param basicDBList {@link BasicDBList} * @return json */ public String serialize(BasicDBList basicDBList) { return JSON.serialize(basicDBList); }
From source file:com.restfeel.controller.rest.EntityDataController.java
License:Apache License
@RequestMapping(value = "/api/{projectId}/entities/{name}/list", method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody String getEntityDataList(@PathVariable("projectId") String projectId, @PathVariable("name") String entityName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "query", required = false) String query, @RequestHeader(value = "authToken", required = false) String authToken) { JSONObject authRes = authService.authorize(projectId, authToken, "USER"); if (!authRes.getBoolean(SUCCESS)) { return authRes.toString(4); }/*from w w w. ja v a 2 s. com*/ DBCollection dbCollection = mongoTemplate.getCollection(projectId + "_" + entityName); DBCursor cursor; if (query != null && !query.isEmpty()) { Object queryObject = JSON.parse(query); cursor = dbCollection.find((BasicDBObject) queryObject); } else { cursor = dbCollection.find(); } if (sort != null && !sort.isEmpty()) { Object sortObject = JSON.parse(sort); cursor.sort((BasicDBObject) sortObject); } if (limit != null && limit > 0) { if (page != null && page > 0) { cursor.skip((page - 1) * limit); } cursor.limit(limit); } List<DBObject> array = cursor.toArray(); if (entityName.equals("User")) { for (DBObject dbObject : array) { dbObject.removeField(PASSWORD); } } for (DBObject dbObject : array) { dbRefToRelation(dbObject); } String json = JSON.serialize(array); // Indentation JSONArray jsonArr = new JSONArray(json); return jsonArr.toString(4); }
From source file:com.restfiddle.controller.rest.EntityDataController.java
License:Apache License
@RequestMapping(value = "/api/{projectId}/entities/{name}/list", method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody String getEntityDataList(@PathVariable("projectId") String projectId, @PathVariable("name") String entityName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "limit", required = false) Integer limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "query", required = false) String query) { DBCollection dbCollection = mongoTemplate.getCollection(entityName); DBCursor cursor = null;/*from w ww. ja v a 2s . com*/ if (query != null && !query.isEmpty()) { Object queryObject = JSON.parse(query); cursor = dbCollection.find((BasicDBObject) queryObject); } else { cursor = dbCollection.find(); } if (sort != null && !sort.isEmpty()) { Object sortObject = JSON.parse(sort); cursor.sort((BasicDBObject) sortObject); } if (limit != null && limit > 0) { if (page != null && page > 0) { cursor.skip((page - 1) * limit); } cursor.limit(limit); } List<DBObject> array = cursor.toArray(); String json = JSON.serialize(array); // Indentation JSONArray jsonArr = new JSONArray(json); return jsonArr.toString(4); }
From source file:com.sfelf.connectors.mongoOplogCursorConnector.java
License:Open Source License
/** * <b>dbobjectToJson</b> - Convert DBObject to Json. * <p/>/*from ww w.ja v a 2 s .c o m*/ * {@sample.xml ../../../doc/mongoOplogCursor-connector.xml.sample mongooplogcursor:dbobjectToJson} * * @param input the input for this transformer * @return the converted string representation */ @Mime(MimeTypes.JSON) @Transformer(sourceTypes = { DBObject.class }) public static String dbobjectToJson(final DBObject input) { return JSON.serialize(input); }