Search in sources :

Example 71 with JsonObjectBuilder

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();
}
Also used : JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 72 with JsonObjectBuilder

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();
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 73 with JsonObjectBuilder

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();
}
Also used : ActionReporter(com.sun.enterprise.v3.common.ActionReporter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 74 with JsonObjectBuilder

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();
}
Also used : JsonException(javax.json.JsonException) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 75 with JsonObjectBuilder

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();
}
Also used : StringWriter(java.io.StringWriter) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Bid(org.jboss.quickstarts.websocket.model.Bid) JsonWriter(javax.json.JsonWriter)

Aggregations

JsonObjectBuilder (javax.json.JsonObjectBuilder)76 JsonArrayBuilder (javax.json.JsonArrayBuilder)31 Map (java.util.Map)19 JsonObject (javax.json.JsonObject)19 JsonException (javax.json.JsonException)14 HashMap (java.util.HashMap)9 StringWriter (java.io.StringWriter)8 ArrayList (java.util.ArrayList)6 JsonValue (javax.json.JsonValue)6 List (java.util.List)5 JsonString (javax.json.JsonString)5 PrintWriter (java.io.PrintWriter)3 Entry (java.util.Map.Entry)3 JsonArray (javax.json.JsonArray)3 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)2 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)2 File (java.io.File)2 JsonWriter (javax.json.JsonWriter)2 Resource (org.apache.sling.api.resource.Resource)2 ValueMap (org.apache.sling.api.resource.ValueMap)2