本文整理汇总了Java中org.bson.Document.toJson方法的典型用法代码示例。如果您正苦于以下问题:Java Document.toJson方法的具体用法?Java Document.toJson怎么用?Java Document.toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.Document
的用法示例。
在下文中一共展示了Document.toJson方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSession
import org.bson.Document; //导入方法依赖的package包/类
@Override
protected String createSession(String sessionId, String customerId, Date creation, Date expiration) {
Document sessionDoc = new Document("_id", sessionId)
.append("customerid", customerId)
.append("lastAccessedTime", creation)
.append("timeoutTime", expiration);
customerSession.insertOne(sessionDoc);
return sessionDoc.toJson();
}
示例2: createAddress
import org.bson.Document; //导入方法依赖的package包/类
@Override
public String createAddress (String streetAddress1, String streetAddress2,
String city, String stateProvince, String country, String postalCode){
Document addressDoc = new Document("streetAddress1", streetAddress1)
.append("city", city)
.append("stateProvince", stateProvince)
.append("country", country)
.append("postalCode", postalCode);
if (streetAddress2 != null){
addressDoc.append("streetAddress2", streetAddress2);
}
return addressDoc.toJson();
}
示例3: getCustomerByUsername
import org.bson.Document; //导入方法依赖的package包/类
@Override
public String getCustomerByUsername(String username) {
Document customerDoc = customer.find(eq("_id", username)).first();
if (customerDoc != null) {
customerDoc.remove("password");
customerDoc.append("password", null);
}
return customerDoc.toJson();
}
示例4: emailConfirm
import org.bson.Document; //导入方法依赖的package包/类
/**
* Confirm a newly registered email in this context
*
* @param token confirmation token emailed to new user
* @param tokenId confirmation tokenId emailed to new user
* @return A task containing whether or not the email was confirmed successfully
*/
public Task<Boolean> emailConfirm(@NonNull final String token, @NonNull final String tokenId) {
final TaskCompletionSource<Boolean> future = new TaskCompletionSource<>();
final String url = String.format(
"%s/%s",
getResourcePath(routes.AUTH),
routes.USERPASS_CONFIRM
);
final Document params = new Document();
params.put("token", token);
params.put("tokenId", tokenId);
final JsonStringRequest request = new JsonStringRequest(
Request.Method.POST,
url,
params.toJson(),
new Response.Listener<String>() {
@Override
public void onResponse(final String response) {
future.setResult(response != null);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(final VolleyError error) {
Log.e(TAG, "Error while confirming email", error);
future.setException(parseRequestError(error));
}
}
);
request.setTag(this);
_queue.add(request);
return future.getTask();
}
示例5: getUser
import org.bson.Document; //导入方法依赖的package包/类
public String getUser(String id) {
FindIterable<Document> jsonUsers
= userCollection
.find(eq("_id", new ObjectId(id)));
Iterator<Document> iterator = jsonUsers.iterator();
Document user = iterator.next();
return user.toJson();
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:12,代码来源:UserController.java
示例6: getFlower
import org.bson.Document; //导入方法依赖的package包/类
public String getFlower(String id) {
FindIterable<Document> jsonFlowers
= flowerCollection
.find(eq("_id", new ObjectId(id)));
Iterator<Document> iterator = jsonFlowers.iterator();
Document flower = iterator.next();
return flower.toJson();
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:12,代码来源:FlowerController.java
示例7: listBeds
import org.bson.Document; //导入方法依赖的package包/类
public String listBeds() {
Document output = new Document();
DistinctIterable<String> beds
= flowerCollection
.distinct("gardenLocation",String.class);
for (String bed: beds){
output.append(bed,bed);
}
return output.toJson();
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:13,代码来源:FlowerController.java
示例8: resetPassword
import org.bson.Document; //导入方法依赖的package包/类
/**
* Reset a given user's password
*
* @param token token associated with this user
* @param tokenId id of the token associated with this user
* @return A task containing whether or not the reset was successful
*/
public Task<Boolean> resetPassword(@NonNull final String token,
@NonNull final String tokenId,
@NonNull final String password) {
final TaskCompletionSource<Boolean> future = new TaskCompletionSource<>();
final String url = String.format(
"%s/%s",
getResourcePath(routes.AUTH),
routes.USERPASS_RESET
);
final Document params = new Document();
params.put(RegistrationFields.TOKEN, token);
params.put(RegistrationFields.TOKEN_ID, tokenId);
params.put(RegistrationFields.PASSWORD, password);
final JsonStringRequest request = new JsonStringRequest(
Request.Method.POST,
url,
params.toJson(),
new Response.Listener<String>() {
@Override
public void onResponse(final String response) {
future.setResult(response != null);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(final VolleyError error) {
Log.e(TAG, "Error while reseting password", error);
future.setException(parseRequestError(error));
}
}
);
request.setTag(this);
_queue.add(request);
return future.getTask();
}
示例9: documentToObject
import org.bson.Document; //导入方法依赖的package包/类
/**
* mongodb转对象格式
*
* @param document
* @param clazz
* @return
*/
public static <T> T documentToObject(Document document, Class<T> clazz) {
Gson gson = new Gson();
String objStr = document.toJson();
T obj = gson.fromJson(objStr, clazz);
return obj;
}