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:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> find(Class<T> entityClass, Map<String, Object> properties, List<String> fields, Integer start, Integer max) { MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); properties.entrySet().stream().filter(e -> { return e.getValue() instanceof List; }).forEach(e -> {/*from w ww . j a v a 2 s . c om*/ Map<String, Object> all = new HashMap<>(); all.put("$all", e.getValue()); properties.put(e.getKey(), all); }); Document filter = new Document(); fields.stream().forEach(f -> filter.put(f, 1)); List<T> result = new ArrayList<>(); collection.find(new Document(properties)).projection(filter).skip(start != null ? start : 0) .limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> findSorted(Class<T> entityClass, Map<String, Object> properties, List<String> fields, Integer start, Integer max, List<String> ascendingFields, List<String> descendingFields) { MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); properties.entrySet().stream().filter(e -> { return e.getValue() instanceof List; }).forEach(e -> {/*from w ww . j a v a 2s . c o m*/ Map<String, Object> all = new HashMap<>(); all.put("$all", e.getValue()); properties.put(e.getKey(), all); }); Document filter = new Document(); fields.stream().forEach(f -> filter.put(f, 1)); List<T> result = new ArrayList<>(); collection.find(new Document(properties)).projection(filter) .sort(Sorts.orderBy(Sorts.ascending(ascendingFields), Sorts.descending(descendingFields))) .skip(start != null ? start : 0).limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> findSortedAsc(Class<T> entityClass, Map<String, Object> properties, List<String> fields, Integer start, Integer max, List<String> ascendingFields) { MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); properties.entrySet().stream().filter(e -> { return e.getValue() instanceof List; }).forEach(e -> {//from w ww .ja va 2 s . co m Map<String, Object> all = new HashMap<>(); all.put("$all", e.getValue()); properties.put(e.getKey(), all); }); Document filter = new Document(); fields.stream().forEach(f -> filter.put(f, 1)); List<T> result = new ArrayList<>(); collection.find(new Document(properties)).projection(filter).sort(Sorts.ascending(ascendingFields)) .skip(start != null ? start : 0).limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> findSortedDesc(Class<T> entityClass, Map<String, Object> properties, List<String> fields, Integer start, Integer max, List<String> descendingFields) { MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); properties.entrySet().stream().filter(e -> { return e.getValue() instanceof List; }).forEach(e -> {/* w w w. j a va 2 s. co m*/ Map<String, Object> all = new HashMap<>(); all.put("$all", e.getValue()); properties.put(e.getKey(), all); }); Document filter = new Document(); fields.stream().forEach(f -> filter.put(f, 1)); List<T> result = new ArrayList<>(); collection.find(new Document(properties)).projection(filter).sort(Sorts.descending(descendingFields)) .skip(start != null ? start : 0).limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> findAll(Class<T> entityClass, Integer start, Integer max) { MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); List<T> result = new ArrayList<>(); collection.find().skip(start != null ? start : 0).limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jaqpot.core.db.entitymanager.MongoDBEntityManager.java
License:Open Source License
@Override public <T extends JaqpotEntity> List<T> findAll(Class<T> entityClass, List<String> fields, Integer start, Integer max) {/*from w w w . j av a 2 s .co m*/ MongoDatabase db = mongoClient.getDatabase(database); MongoCollection<Document> collection = db.getCollection(collectionNames.get(entityClass)); List<T> result = new ArrayList<>(); Document filter = new Document(); fields.stream().forEach(f -> filter.put(f, 1)); collection.find().projection(filter).skip(start != null ? start : 0) .limit(max != null ? max : DEFAULT_PAGE_SIZE) .map(document -> serializer.parse(JSON.serialize(document), entityClass)).into(result); return result; }
From source file:org.jongo.marshall.jackson.NativeSerializer.java
License:Apache License
public void serialize(Object obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeRawValue(JSON.serialize(obj)); }
From source file:org.jongo.query.JsonQueryFactory.java
License:Apache License
private Object marshallParameter(Object parameter, boolean serializeBsonPrimitives) { try {//from w ww. j ava 2 s . com if (parameter == null || Bson.isPrimitive(parameter)) { return serializeBsonPrimitives ? JSON.serialize(parameter) : parameter; } if (parameter instanceof Enum) { String name = ((Enum) parameter).name(); return serializeBsonPrimitives ? JSON.serialize(name) : name; } if (parameter instanceof List) { return marshallArray(((List) parameter).toArray()); } if (parameter instanceof Object[]) { return marshallArray((Object[]) parameter); } return marshallDocument(parameter); } catch (Exception e) { String message = String.format("Unable to marshall parameter: %s", parameter); throw new MarshallingException(message, e); } }
From source file:org.jsonbuilder.implementations.mongodb.MongoDbArrayNode.java
License:Apache License
public String toString() { return JSON.serialize(list); }
From source file:org.mule.module.mongo.MongoCloudConnector.java
License:Open Source License
/** * Convert a BasicBSONList into Json.//from w w w . j a va 2 s . c o m * <p/> * {@sample.xml ../../../doc/mongo-connector.xml.sample mongo:bsonListToJson} * * @param input the input for this transformer * @return the converted string representation */ @Mime(MimeTypes.JSON) @Transformer(sourceTypes = { BasicBSONList.class }) public static String bsonListToJson(final BasicBSONList input) { return JSON.serialize(input); }