use of javax.json.JsonObjectBuilder in project Payara by payara.
the class RestResourceMetadata method toJson.
public JsonObject toJson() throws JsonException {
JsonObjectBuilder o = Json.createObjectBuilder();
if (!resourceMethods.isEmpty()) {
final JsonObjectBuilder methods = Json.createObjectBuilder();
for (String key : resourceMethods.keySet()) {
for (RestMethodMetadata rmm : resourceMethods.get(key)) {
methods.add(key, rmm.toJson());
}
}
o.add("resourceMethods", methods);
}
if (!subResources.isEmpty()) {
o.add("subResources", JsonUtil.getJsonValue(subResources));
}
return o.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class LegacySseResponseBody method toJson.
@Override
public JsonObject toJson() throws JsonException {
JsonObjectBuilder jsonBuild = Json.createObjectBuilder(super.toJson());
if (!headers.isEmpty()) {
JsonObjectBuilder oBuild = Json.createObjectBuilder();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
final String key = entry.getKey();
for (String value : entry.getValue()) {
oBuild.add(key, value);
}
}
jsonBuild.add("headers", oBuild);
}
return jsonBuild.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class Message method toJson.
public JsonObject toJson() throws JsonException {
JsonObjectBuilder object = Json.createObjectBuilder();
object.add("message", getMessage());
object.add("severity", getSeverity().toString());
String f = getField();
if (f != null && f.length() > 0) {
object.add("field", f);
}
return object.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class ActionReportJson2Provider method processReport.
@Override
protected JsonObject processReport(ActionReporter ar) throws JsonException {
JsonObject result = super.processReport(ar);
JsonObjectBuilder objectBuilder = Json.createObjectBuilder(result);
String combinedMessage = result.getString("message", null);
String msg = decodeEol(ar.getTopMessagePart().getMessage());
if (combinedMessage != null && !combinedMessage.equals(msg)) {
if (msg != null) {
objectBuilder.add("top_message", msg);
} else {
objectBuilder.add("top_message", JsonValue.NULL);
}
}
if (ar.getFailureCause() != null) {
objectBuilder.add("failure_cause", ar.getFailureCause().getLocalizedMessage());
}
return objectBuilder.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class ActionReportJsonProvider method processReport.
/**
* Converts an ActionReport into a JsonObject
* @param ar
* @return
* @throws JsonException
*/
protected JsonObject processReport(ActionReporter ar) throws JsonException {
JsonObjectBuilder result = Json.createObjectBuilder();
if (ar instanceof RestActionReporter) {
result.add("message", ((RestActionReporter) ar).getCombinedMessage());
} else {
String message = decodeEol(ar.getMessage());
if (message != null) {
result.add("message", message);
}
}
String desc = ar.getActionDescription();
if (desc != null) {
result.add("command", ar.getActionDescription());
} else {
result.add("command", JsonValue.NULL);
}
result.add("exit_code", ar.getActionExitCode().toString());
Properties properties = ar.getTopMessagePart().getProps();
if ((properties != null) && (!properties.isEmpty())) {
JsonObject propBuilder = Json.createObjectBuilder((Map) properties).build();
result.add("properties", propBuilder);
}
Properties extraProperties = ar.getExtraProperties();
if ((extraProperties != null) && (!extraProperties.isEmpty())) {
result.add("extraProperties", getExtraProperties(extraProperties));
}
List<MessagePart> children = ar.getTopMessagePart().getChildren();
if ((children != null) && (!children.isEmpty())) {
result.add("children", processChildren(children));
}
List<ActionReporter> subReports = ar.getSubActionsReport();
if ((subReports != null) && (!subReports.isEmpty())) {
result.add("subReports", processSubReports(subReports));
}
return result.build();
}
Aggregations