use of javax.json.JsonArrayBuilder in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonValidationLoggerHelper method buildResponse.
private JsonObject buildResponse(final ValidationException validationException) {
final JsonObjectBuilder builder = createObjectBuilder();
Optional.ofNullable(validationException.getMessage()).ifPresent(message -> builder.add("message", message));
Optional.ofNullable(validationException.getViolatedSchema()).ifPresent(schema -> builder.add("violatedSchema", getSchemaName(schema)));
Optional.ofNullable(validationException.getPointerToViolation()).ifPresent(violation -> builder.add("violation", violation));
final JsonArrayBuilder arrayBuilder = createArrayBuilder();
validationException.getCausingExceptions().forEach(exception -> arrayBuilder.add(buildResponse(exception)));
builder.add("causingExceptions", arrayBuilder.build());
return builder.build();
}
use of javax.json.JsonArrayBuilder in project microservice_framework by CJSCommonPlatform.
the class DefaultJsonEnvelope method toString.
@Override
public String toString() {
final JsonObjectBuilder builder = Json.createObjectBuilder();
if (metadata != null) {
builder.add("id", String.valueOf(metadata.id())).add("name", metadata.name());
metadata.clientCorrelationId().ifPresent(s -> builder.add(CORRELATION, s));
metadata.sessionId().ifPresent(s -> builder.add(SESSION_ID, s));
metadata.userId().ifPresent(s -> builder.add(USER_ID, s));
final JsonArrayBuilder causationBuilder = Json.createArrayBuilder();
final List<UUID> causes = metadata.causation();
if (causes != null) {
metadata.causation().forEach(uuid -> causationBuilder.add(String.valueOf(uuid)));
}
builder.add("causation", causationBuilder);
}
return builder.build().toString();
}
use of javax.json.JsonArrayBuilder in project fabric-sdk-java by hyperledger.
the class RegistrationRequest method toJsonObject.
// Convert the registration request to a JSON object
JsonObject toJsonObject() {
JsonObjectBuilder ob = Json.createObjectBuilder();
ob.add("id", enrollmentID);
ob.add("type", type);
if (this.secret != null) {
ob.add("secret", secret);
}
if (null != maxEnrollments) {
ob.add("max_enrollments", maxEnrollments);
}
if (affiliation != null) {
ob.add("affiliation", affiliation);
}
JsonArrayBuilder ab = Json.createArrayBuilder();
for (Attribute attr : attrs) {
ab.add(attr.toJsonObject());
}
if (caName != null) {
ob.add(HFCAClient.FABRIC_CA_REQPROP, caName);
}
ob.add("attrs", ab.build());
return ob.build();
}
use of javax.json.JsonArrayBuilder in project Manga by herrlock.
the class MDObject method handle.
@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
logger.traceEntry();
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
for (Entry<UUID, MDObject> entry : this.dlContext.entrySet()) {
UUID key = entry.getKey();
MDObject value = entry.getValue();
MDownloader mdownloader = value.getMdownloader();
arrayBuilder.add(//
Json.createObjectBuilder().add("uuid", //
key.toString()).add("url", //
value.getUrl()).add("started", //
mdownloader.getStarted()).add("progress", //
mdownloader.getProgress()).add("maxProgress", mdownloader.getMaxProgress()));
}
Json.createWriter(response.getOutputStream()).write(arrayBuilder.build());
response.setContentType(MediaType.JSON_UTF_8.toString());
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
}
use of javax.json.JsonArrayBuilder in project dataverse by IQSS.
the class UtilIT method createDataverse.
static Response createDataverse(String alias, String category, String apiToken) {
JsonArrayBuilder contactArrayBuilder = Json.createArrayBuilder();
contactArrayBuilder.add(Json.createObjectBuilder().add("contactEmail", getEmailFromUserName(getRandomIdentifier())));
JsonArrayBuilder subjectArrayBuilder = Json.createArrayBuilder();
subjectArrayBuilder.add("Other");
JsonObject dvData = Json.createObjectBuilder().add("alias", alias).add("name", alias).add("dataverseContacts", contactArrayBuilder).add("dataverseSubjects", subjectArrayBuilder).add(category != null ? "dataverseType" : "notTheKeyDataverseType", category != null ? category : "whatever").build();
Response createDataverseResponse = given().body(dvData.toString()).contentType(ContentType.JSON).when().post("/api/dataverses/:root?key=" + apiToken);
return createDataverseResponse;
}
Aggregations