本文整理汇总了Java中javax.json.JsonObject.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.isEmpty方法的具体用法?Java JsonObject.isEmpty怎么用?Java JsonObject.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.isEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateOccasion
import javax.json.JsonObject; //导入方法依赖的package包/类
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateOccasion(@PathParam("id") String id, JsonObject json) {
String method = "updateOccasion";
logger.entering(clazz, method, new Object[] {id, json});
// Validate the JWT. At this point, anyone can update an occasion
// if they have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
logger.exiting(clazz, method, Status.UNAUTHORIZED);
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
Response response = Response.ok().build();
// Ensure we recieved a valid ID
if (!ObjectId.isValid(id) || null == json || json.isEmpty()) {
response = Response.status(400).entity("invalid occasion id").build();
} else {
// perform the update using $set to prevent overwriting data in the event of an incomplete
// payload
Occasion updatedOccasion = new Occasion(json);
BasicDBObject updateObject = new BasicDBObject("$set", updatedOccasion.toDbo());
BasicDBObject query = new BasicDBObject(Occasion.OCCASION_ID_KEY, new ObjectId(id));
// Update and return the new document.
DBObject updatedObject =
getCollection().findAndModify(query, null, null, false, updateObject, true, false);
// Reschedule occasion with the orchestrator. Use the updated object from
// mongo because it will contain all fields that the orchestator may need.
try {
orchestrator.cancelOccasion(id);
orchestrator.scheduleOccasion(new Occasion(updatedObject));
} catch (ParseException e) {
e.printStackTrace();
response =
Response.status(400).entity("Invalid date given. Format must be YYYY-MM-DD").build();
}
}
logger.exiting(clazz, method, response);
return response;
}