use of javax.json.JsonArrayBuilder in project cxf by apache.
the class BookJsonStore method bookToJson.
private JsonObject bookToJson(final Book book) {
final JsonObjectBuilder builder = Json.createObjectBuilder().add("id", book.getId()).add("name", book.getName());
if (!book.getChapters().isEmpty()) {
final JsonArrayBuilder chapters = Json.createArrayBuilder();
for (final BookChapter chapter : book.getChapters()) {
chapters.add(Json.createObjectBuilder().add("id", chapter.getId()).add("title", chapter.getTitle()));
}
builder.add("chapters", chapters);
}
return builder.build();
}
use of javax.json.JsonArrayBuilder in project quickstart by wildfly.
the class TokenUtil method generateJWT.
public static String generateJWT(final String principal, final String birthdate, final String... groups) throws Exception {
PrivateKey privateKey = loadPrivateKey("private.pem");
JWSSigner signer = new RSASSASigner(privateKey);
JsonArrayBuilder groupsBuilder = Json.createArrayBuilder();
for (String group : groups) {
groupsBuilder.add(group);
}
long currentTime = System.currentTimeMillis() / 1000;
JsonObjectBuilder claimsBuilder = Json.createObjectBuilder().add("sub", principal).add("upn", principal).add("iss", "quickstart-jwt-issuer").add("aud", "jwt-audience").add("groups", groupsBuilder.build()).add("birthdate", birthdate).add("jti", UUID.randomUUID().toString()).add("iat", currentTime).add("exp", currentTime + 14400);
JWSObject jwsObject = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256).type(new JOSEObjectType("jwt")).keyID("Test Key").build(), new Payload(claimsBuilder.build().toString()));
jwsObject.sign(signer);
return jwsObject.serialize();
}
use of javax.json.JsonArrayBuilder in project opentheso by miledrousset.
the class Rest_new method getlistAllPublicTheso__.
private String getlistAllPublicTheso__(HikariDataSource ds) {
ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
List<String> listPublicTheso = thesaurusHelper.getAllIdOfThesaurus(ds, false);
NodeThesaurus nodeThesaurus;
String datasJson;
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
for (String idTheso : listPublicTheso) {
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("idTheso", idTheso);
JsonArrayBuilder jsonArrayBuilderLang = Json.createArrayBuilder();
nodeThesaurus = thesaurusHelper.getNodeThesaurus(ds, idTheso);
for (Thesaurus thesaurus : nodeThesaurus.getListThesaurusTraduction()) {
JsonObjectBuilder jobLang = Json.createObjectBuilder();
jobLang.add("lang", thesaurus.getLanguage());
jobLang.add("title", thesaurus.getTitle());
jsonArrayBuilderLang.add(jobLang.build());
}
if (!nodeThesaurus.getListThesaurusTraduction().isEmpty()) {
job.add("labels", jsonArrayBuilderLang.build());
}
jsonArrayBuilder.add(job.build());
}
datasJson = jsonArrayBuilder.build().toString();
if (datasJson != null)
return datasJson;
else
return null;
}
use of javax.json.JsonArrayBuilder in project jersey by jersey.
the class DocumentFilteringResource method filter.
@POST
public JsonArray filter(final JsonArray properties) {
final JsonArrayBuilder documents = Json.createArrayBuilder();
final List<JsonString> propertyList = properties.getValuesAs(JsonString.class);
for (final JsonObject jsonObject : DocumentStorage.getAll()) {
final JsonObjectBuilder documentBuilder = Json.createObjectBuilder();
for (final JsonString property : propertyList) {
final String key = property.getString();
if (jsonObject.containsKey(key)) {
documentBuilder.add(key, jsonObject.get(key));
}
}
final JsonObject document = documentBuilder.build();
if (!document.isEmpty()) {
documents.add(document);
}
}
return documents.build();
}
use of javax.json.JsonArrayBuilder in project torodb by torodb.
the class ToroIndexConverter method to.
@Override
public String to(NamedToroIndex userObject) {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
objectBuilder.add(NAME_KEY, userObject.getName());
if (userObject.isUnique()) {
objectBuilder.add(UNIQUE_KEY, true);
}
JsonArrayBuilder attsBuilder = Json.createArrayBuilder();
JsonArrayBuilder descBuilder = Json.createArrayBuilder();
int attPosition = 0;
boolean hasDescending = false;
for (Map.Entry<AttributeReference, IndexType> entry : userObject.getAttributes().entrySet()) {
attsBuilder.add(entry.getKey().toString());
if (IndexType.desc.equals(entry.getValue())) {
descBuilder.add(attPosition);
hasDescending = true;
}
attPosition++;
}
objectBuilder.add(ATTS_KEY, attsBuilder);
if (hasDescending) {
objectBuilder.add(DESCENDING, descBuilder);
}
StringWriter stringWriter = new StringWriter(200);
JsonWriter jsonWriter = Json.createWriter(stringWriter);
jsonWriter.writeObject(objectBuilder.build());
return stringWriter.toString();
}
Aggregations