use of javax.json.JsonArray in project scylla-jmx by scylladb.
the class StreamManager method getState.
public Set<StreamState> getState() {
JsonArray arr = client.getJsonArray("/stream_manager/");
Set<StreamState> res = new HashSet<StreamState>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.getJsonObject(i);
res.add(new StreamState(obj.getString("plan_id"), obj.getString("description"), SessionInfo.fromJsonArr(obj.getJsonArray("sessions"))));
}
return res;
}
use of javax.json.JsonArray in project knime-core by knime.
the class OpenAPIDefinitionGenerator method translateToSchema.
private static JsonObjectBuilder translateToSchema(final JsonValue v) {
final JsonObjectBuilder node = Json.createObjectBuilder();
if (v instanceof JsonObject) {
node.add("type", "object");
final JsonObjectBuilder properties = Json.createObjectBuilder();
for (Map.Entry<String, JsonValue> e : ((JsonObject) v).entrySet()) {
final JsonObjectBuilder child = translateToSchema(e.getValue());
properties.add(e.getKey(), child);
}
node.add("properties", properties);
} else if (v instanceof JsonNumber) {
final JsonNumber number = (JsonNumber) v;
if (number.isIntegral()) {
node.add("type", "integer");
node.add("default", number.longValue());
} else {
node.add("type", "number");
node.add("default", number.doubleValue());
}
} else if (v instanceof JsonString) {
node.add("type", "string");
node.add("default", ((JsonString) v).getString());
} else if ((v.getValueType() == ValueType.FALSE) || (v.getValueType() == ValueType.TRUE)) {
node.add("type", "boolean");
node.add("default", v.toString());
} else if (v instanceof JsonArray) {
node.add("type", "array");
if (!((JsonArray) v).isEmpty()) {
JsonObjectBuilder child = translateToSchema(((JsonArray) v).get(0));
node.add("items", child);
}
}
return node;
}
use of javax.json.JsonArray in project cxf by apache.
the class JsrJsonpProviderTest method testPostAndGetBooks.
@Test
public void testPostAndGetBooks() {
testPostSimpleJsonObject();
final Response r = createWebClient("/bookstore/books").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
final JsonArray obj = r.readEntity(JsonArray.class);
assertThat(obj.size(), equalTo(1));
assertThat(obj.get(0), instanceOf(JsonObject.class));
assertThat(((JsonObject) obj.get(0)).getInt("id"), equalTo(1));
assertThat(((JsonObject) obj.get(0)).getString("name"), equalTo("Book 1"));
}
use of javax.json.JsonArray in project Payara by payara.
the class RemoteRestAdminCommand method parseMetadata.
/**
* Parse the JSon metadata for the command.
*
* @param str the string
* @return the etag to compare the command cache model
*/
private CachedCommandModel parseMetadata(String str, String etag) {
if (logger.isLoggable(Level.FINER)) {
// XXX - assume "debug" == "FINER"
logger.finer("------- RAW METADATA RESPONSE ---------");
logger.log(Level.FINER, "ETag: {0}", etag);
logger.finer(str);
logger.finer("------- RAW METADATA RESPONSE ---------");
}
if (str == null) {
return null;
}
try {
boolean sawFile = false;
JsonParser parser = Json.createParser(new StringReader(str));
parser.next();
JsonObject obj = parser.getObject();
obj = obj.getJsonObject("command");
CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
cm.dashOk = parseBoolean(obj, "@unknown-options-are-operands", false);
cm.managedJob = parseBoolean(obj, "@managed-job", false);
cm.setUsage(obj.getString("usage", null));
JsonValue optns = obj.get("option");
if (!JsonValue.NULL.equals(optns) && optns != null) {
JsonArray jsonOptions;
if (optns instanceof JsonArray) {
jsonOptions = (JsonArray) optns;
} else {
JsonArrayBuilder optBuilder = Json.createArrayBuilder();
optBuilder.add(optns);
jsonOptions = optBuilder.build();
}
for (int i = 0; i < jsonOptions.size(); i++) {
JsonObject jsOpt = jsonOptions.getJsonObject(i);
String type = jsOpt.getString("@type");
ParamModelData opt = new ParamModelData(jsOpt.getString("@name"), typeOf(type), parseBoolean(jsOpt, "@optional", false), jsOpt.getString("@default", null), jsOpt.getString("@short", null), parseBoolean(jsOpt, "@obsolete", false), jsOpt.getString("@alias", null));
opt.param._acceptableValues = jsOpt.getString("@acceptable-values", "");
if ("PASSWORD".equals(type)) {
opt.param._password = true;
opt.prompt = jsOpt.getString("@prompt", null);
opt.promptAgain = jsOpt.getString("@prompt-again", null);
} else if ("FILE".equals(type)) {
sawFile = true;
}
if (parseBoolean(jsOpt, "@primary", false)) {
opt.param._primary = true;
}
if (parseBoolean(jsOpt, "@multiple", false)) {
if (opt.type == File.class) {
opt.type = File[].class;
} else {
opt.type = List.class;
}
opt.param._multiple = true;
}
cm.add(opt);
}
}
if (sawFile) {
cm.add(new ParamModelData("upload", Boolean.class, true, null));
addedUploadOption = true;
cm.setAddedUploadOption(true);
}
if (notify) {
cm.add(new ParamModelData("notify", Boolean.class, false, "false"));
}
this.usage = cm.getUsage();
return cm;
} catch (Exception ex) {
logger.log(Level.SEVERE, "Can not parse command metadata", ex);
return null;
}
}
use of javax.json.JsonArray in project Payara by payara.
the class ActionReportJsonProprietaryReader method fillActionReport.
/**
* Turns a {@link JsonObject} into an {@link ActionReport}
* <p>
* The Json Object must contain a valid {@code exit_code} at the top level.
* @param ar
* @param json
* @throws JsonException
*/
public static void fillActionReport(final ActionReport ar, final JsonObject json) throws JsonException {
ar.setActionExitCode(ActionReport.ExitCode.valueOf(json.getString("exit_code")));
ar.setActionDescription(json.getString("command", null));
String failure = json.getString("failure_cause", null);
if (failure != null && !failure.isEmpty()) {
ar.setFailureCause(new Exception(failure));
}
ar.setExtraProperties((Properties) extractMap(json.getJsonObject("extraProperties"), new Properties()));
ar.getTopMessagePart().setMessage(json.getString("top_message", json.getString("message", null)));
Properties props = (Properties) extractMap(json.getJsonObject("properties"), new Properties());
for (Map.Entry entry : props.entrySet()) {
Object entryValue = entry.getValue();
// See difference between JsonString.toString and JsonString.getValue
if (entryValue instanceof JsonString) {
ar.getTopMessagePart().addProperty(String.valueOf(entry.getKey()), ((JsonString) entry.getValue()).getString());
} else {
ar.getTopMessagePart().addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
}
// Sub messages
fillSubMessages(ar.getTopMessagePart(), json.getJsonArray("children"));
// Sub action reports
JsonArray subJsons = json.getJsonArray("subReports");
if (subJsons != null) {
for (int i = 0; i < subJsons.size(); i++) {
JsonObject subJson = subJsons.getJsonObject(i);
fillActionReport(ar.addSubActionsReport(), subJson);
}
}
}
Aggregations