use of javax.json.JsonString 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);
}
}
}
use of javax.json.JsonString in project Payara by payara.
the class ActionReportJsonProprietaryReader method fillSubMessages.
/**
* Fills all messages below top_message of an action report
* @param mp
* @param json
* @throws JsonException
*/
private static void fillSubMessages(final ActionReport.MessagePart mp, final JsonArray json) throws JsonException {
if (json == null) {
return;
}
for (int i = 0; i < json.size(); i++) {
JsonObject subJson = json.getJsonObject(i);
MessagePart child = mp.addChild();
child.setMessage(subJson.getString("message", null));
Properties props = (Properties) extractMap(subJson.getJsonObject("properties"), new Properties());
for (Map.Entry entry : props.entrySet()) {
Object entryValue = entry.getValue();
if (entryValue instanceof JsonString) {
child.addProperty(String.valueOf(entry.getKey()), ((JsonString) entry.getValue()).getString());
} else {
child.addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
child.addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
fillSubMessages(child, subJson.getJsonArray("children"));
}
}
use of javax.json.JsonString in project Payara by payara.
the class CompositeUtil method unmarshallClass.
/**
* Convert the given <code>RestModel</code> encoded as Json to a live Java Object.
*
* @param locale
* @param modelClass The target <code>RestModel</code> type
* @param json The json encoding of the object
* @return
*/
public <T> T unmarshallClass(Locale locale, Class<T> modelClass, JsonObject json) throws JsonException {
T model = getModel(modelClass);
for (Method setter : getSetters(modelClass)) {
String name = setter.getName();
String attribute = name.substring(3, 4).toLowerCase(Locale.getDefault()) + name.substring(4);
Type param0 = setter.getGenericParameterTypes()[0];
Class class0 = setter.getParameterTypes()[0];
if (json.containsKey(attribute)) {
java.lang.Object o = json.get(attribute);
if (JsonArray.class.isAssignableFrom(o.getClass())) {
Object values = processJsonArray(locale, param0, (JsonArray) o);
invoke(locale, setter, attribute, model, values);
} else if (JsonObject.class.isAssignableFrom(o.getClass())) {
invoke(locale, setter, attribute, model, unmarshallClass(locale, class0, (JsonObject) o));
} else if (JsonString.class.isAssignableFrom(o.getClass())) {
System.out.println(o);
invoke(locale, setter, attribute, model, ((JsonString) o).getString());
} else if (JsonNumber.class.isAssignableFrom(o.getClass())) {
invoke(locale, setter, attribute, model, ((JsonNumber) o).numberValue());
} else {
if ("null".equals(o.toString())) {
o = null;
} else if ("true".equals(o.toString())) {
o = true;
} else if ("false".equals(o.toString())) {
o = false;
}
if (!isUnmodifiedConfidentialProperty(modelClass, name, o)) {
invoke(locale, setter, attribute, model, o);
}
}
}
}
return model;
}
use of javax.json.JsonString in project Payara by payara.
the class MBeanAttributeReadHandlerTest method getValueObject_String.
@Test
public void getValueObject_String() throws Exception {
MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE);
when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn("Payara");
JsonValue value = handler.getValueObject();
assertThat(value.getValueType()).isEqualTo(JsonValue.ValueType.STRING);
assertThat(((JsonString) value).getString()).isEqualTo("Payara");
}
use of javax.json.JsonString in project knime-core by knime.
the class HubStatistics method getStatistics.
/**
* Gets the statistics for the specified key.
*
* @param key The key of the statistics.
* @return The value, or <code>null</code> if no such value exists.
*/
private static String getStatistics(final String key) {
try {
final JsonObject stats = readHubStats(getStatisticsLocation());
final JsonValue val = stats.get(key);
if (val instanceof JsonString) {
return ((JsonString) val).getString();
}
} catch (Exception ex) {
}
return null;
}
Aggregations