本文整理了Java中play.libs.Json.newObject()
方法的一些代码示例,展示了Json.newObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.newObject()
方法的具体详情如下:
包路径:play.libs.Json
类名称:Json
方法名:newObject
[英]Creates a new empty ObjectNode.
[中]创建新的空ObjectNode。
代码示例来源:origin: com.typesafe.play/play_2.11
private JsonNode error(JsonNode content) {
ObjectNode result = Json.newObject();
result.set("error", content);
return result;
}
代码示例来源:origin: com.typesafe.play/play_2.12
private JsonNode error(JsonNode content) {
ObjectNode result = Json.newObject();
result.set("error", content);
return result;
}
代码示例来源:origin: com.typesafe.play/play
private JsonNode error(JsonNode content) {
ObjectNode result = Json.newObject();
result.set("error", content);
return result;
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Invoked in prod mode when a server error occurs.
*
* Override this rather than {@link #onServerError(RequestHeader, Throwable)} if you don't want to change Play's debug output when logging errors
* in dev mode.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode prodServerError(RequestHeader request, UsefulException exception) {
ObjectNode result = Json.newObject();
result.put("id", exception.id);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play
/**
* Invoked in prod mode when a server error occurs.
*
* Override this rather than {@link #onServerError(RequestHeader, Throwable)} if you don't want to change Play's debug output when logging errors
* in dev mode.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode prodServerError(RequestHeader request, UsefulException exception) {
ObjectNode result = Json.newObject();
result.put("id", exception.id);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Invoked in prod mode when a server error occurs.
*
* Override this rather than {@link #onServerError(RequestHeader, Throwable)} if you don't want to change Play's debug output when logging errors
* in dev mode.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode prodServerError(RequestHeader request, UsefulException exception) {
ObjectNode result = Json.newObject();
result.put("id", exception.id);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Invoked in dev mode when a server error occurs.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode devServerError(RequestHeader request, UsefulException exception) {
ObjectNode exceptionJson = Json.newObject();
exceptionJson.put("title", exception.title);
exceptionJson.put("description", exception.description);
exceptionJson.set("stacktrace", formatDevServerErrorException(exception.cause));
ObjectNode result = Json.newObject();
result.put("id", exception.id);
result.put("requestId", request.asScala().id());
result.set("exception", exceptionJson);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play
/**
* Invoked in dev mode when a server error occurs.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode devServerError(RequestHeader request, UsefulException exception) {
ObjectNode exceptionJson = Json.newObject();
exceptionJson.put("title", exception.title);
exceptionJson.put("description", exception.description);
exceptionJson.set("stacktrace", formatDevServerErrorException(exception.cause));
ObjectNode result = Json.newObject();
result.put("id", exception.id);
result.put("requestId", request.asScala().id());
result.set("exception", exceptionJson);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Invoked in dev mode when a server error occurs.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected JsonNode devServerError(RequestHeader request, UsefulException exception) {
ObjectNode exceptionJson = Json.newObject();
exceptionJson.put("title", exception.title);
exceptionJson.put("description", exception.description);
exceptionJson.set("stacktrace", formatDevServerErrorException(exception.cause));
ObjectNode result = Json.newObject();
result.put("id", exception.id);
result.put("requestId", request.asScala().id());
result.set("exception", exceptionJson);
return error(result);
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
if (!play.api.http.Status$.MODULE$.isClientError(statusCode)) {
throw new IllegalArgumentException(
"onClientError invoked with non client error status code " + statusCode + ": " + message);
}
ObjectNode result = Json.newObject();
result.put("requestId", request.asScala().id());
result.put("message", message);
return CompletableFuture.completedFuture(Results.status(statusCode, error(result)));
}
代码示例来源:origin: com.typesafe.play/play
@Override
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
if (!play.api.http.Status$.MODULE$.isClientError(statusCode)) {
throw new IllegalArgumentException(
"onClientError invoked with non client error status code " + statusCode + ": " + message);
}
ObjectNode result = Json.newObject();
result.put("requestId", request.asScala().id());
result.put("message", message);
return CompletableFuture.completedFuture(Results.status(statusCode, error(result)));
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
if (!play.api.http.Status$.MODULE$.isClientError(statusCode)) {
throw new IllegalArgumentException(
"onClientError invoked with non client error status code " + statusCode + ": " + message);
}
ObjectNode result = Json.newObject();
result.put("requestId", request.asScala().id());
result.put("message", message);
return CompletableFuture.completedFuture(Results.status(statusCode, error(result)));
}
代码示例来源:origin: si.urbas/pless
public static Results.Status error(String message) {
return badRequestJson(Json.newObject().put(RESPONSE_FIELD_ERROR, message));
}
}
代码示例来源:origin: si.urbas/pless
public static Results.Status message(String message) {
return okJson(Json.newObject().put(RESPONSE_FIELD_MESSAGE, message));
}
代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac
@Override
public void setHerculesMatches(String userId, AcHost acHost, Issue issue, final List<Pattern> patterns)
{
LOGGER.trace("Setting hercules property on issue {} to {} matches", issue.getKey(), patterns.size());
final ObjectNode herculesProperty = Json.newObject();
herculesProperty.put("matches", patterns.size());
herculesProperty.put("articles", patterns.stream().map(Pattern::getPageName).collect(Collectors.joining("|")));
final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/properties/hercules", acHost, Option.none()).setContentType("application/json");
final WS.Response response = url.put(herculesProperty).get(30, TimeUnit.SECONDS);
// HTTP 201 created
if (response.getStatus() >= 400)
{
LOGGER.error("Error setting 'hercules' property on issue {}, response [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText());
}
else
{
LOGGER.trace("Property 'hercules' set on issue {}", issue.getKey());
}
}
}
代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac
private void addComment(final AcHost acHost, final Issue issue, final String commentBody)
{
LOGGER.debug("Adding comment to the issue {}", issue.getKey());
final ObjectNode commentJson = Json.newObject();
commentJson.put("body", commentBody);
final WS.WSRequestHolder url = AC.url("/rest/api/2/issue/" + issue.getKey() + "/comment", acHost, Option.none()).setContentType("application/json");
final WS.Response response = url.post(commentJson).get(30, TimeUnit.SECONDS);
// HTTP 201 created
if (response.getStatus() != 201)
{
LOGGER.error("Error adding comment to the issue {}, [{}] {}", issue.getKey(), response.getStatus(), response.getStatusText());
}
else
{
LOGGER.debug("Successfully added comment to the issue {}", issue.getKey());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!