use of javax.json.JsonObjectBuilder in project Payara by payara.
the class ActionReportJsonProvider method getExtraProperties.
protected JsonObject getExtraProperties(Properties props) throws JsonException {
JsonObjectBuilder extraProperties = Json.createObjectBuilder();
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String key = entry.getKey().toString();
Object value = JsonUtil.getJsonValue(entry.getValue());
extraProperties.add(key, JsonUtil.getJsonValue(value));
}
return extraProperties.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class ActionReportJsonProvider method processChildren.
protected JsonArray processChildren(List<MessagePart> parts) throws JsonException {
JsonArrayBuilder array = Json.createArrayBuilder();
for (MessagePart part : parts) {
JsonObjectBuilder object = Json.createObjectBuilder();
String message = decodeEol(part.getMessage());
if (message != null) {
object.add("message", decodeEol(part.getMessage()));
} else {
object.add("message", JsonValue.NULL);
}
object.add("properties", Json.createObjectBuilder((Map) part.getProps()).build());
List<MessagePart> children = part.getChildren();
if (children.size() > 0) {
object.add("children", processChildren(part.getChildren()));
}
array.add(object.build());
}
return array.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class AdminCommandStateJsonProvider method processState.
public JsonObject processState(AdminCommandState state) throws JsonException {
JsonObjectBuilder result = Json.createObjectBuilder();
result.add("state", state.getState().name());
result.add("id", state.getId());
result.add("empty-payload", state.isOutboundPayloadEmpty());
ActionReporter ar = (ActionReporter) state.getActionReport();
addActionReporter(ar, result);
return result.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class GetResultListJsonProvider method getContent.
@Override
public String getContent(GetResultList proxy) {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
objectBuilder.add(KEY_ENTITY, JsonValue.EMPTY_JSON_OBJECT);
objectBuilder.add(KEY_METHODS, getJsonForMethodMetaData(proxy.getMetaData()));
if (proxy.getDomList().size() > 0) {
objectBuilder.add(KEY_CHILD_RESOURCES, getResourcesLinks(proxy.getDomList()));
}
if (proxy.getCommandResourcesPaths().length > 0) {
objectBuilder.add(KEY_COMMANDS, getCommandLinks(proxy.getCommandResourcesPaths()));
}
} catch (JsonException ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
return objectBuilder.build().toString();
}
use of javax.json.JsonObjectBuilder in project quickstart by wildfly.
the class BiddingEncoder method encode.
@Override
public String encode(Bidding bidding) throws EncodeException {
// It uses the JSON-P API to create a JSON representation
JsonObjectBuilder jsonBuilder = Json.createObjectBuilder().add("item", Json.createObjectBuilder().add("buyNowPrice", bidding.getItem().getBuyNowPrice()).add("description", bidding.getItem().getDescription()).add("imagePath", bidding.getItem().getImagePath()).add("title", bidding.getItem().getTitle()).build()).add("bidStatus", bidding.getBidStatus().toString()).add("currentPrice", bidding.getCurrentPrice()).add("secondsLeft", 0);
if (bidding.getDueDate() != null) {
jsonBuilder.add("dueDate", bidding.getDueDate().getTime());
}
if (bidding.getSecondsLeft() != null) {
jsonBuilder.add("secondsLeft", bidding.getSecondsLeft());
}
JsonArrayBuilder jsonBidArray = Json.createArrayBuilder();
for (Bid bid : bidding.getBids()) {
jsonBidArray.add(Json.createObjectBuilder().add("dateTime", bid.getDateTime().getTime()).add("value", bid.getValue()).add("id", bid.getId()).build());
}
jsonBuilder.add("bids", jsonBidArray);
StringWriter stWriter = new StringWriter();
JsonWriter jsonWriter = Json.createWriter(stWriter);
jsonWriter.writeObject(jsonBuilder.build());
jsonWriter.close();
return stWriter.toString();
}
Aggregations