Example usage for javax.json JsonObjectBuilder build

List of usage examples for javax.json JsonObjectBuilder build

Introduction

In this page you can find the example usage for javax.json JsonObjectBuilder build.

Prototype

JsonObject build();

Source Link

Document

Returns the JSON object associated with this object builder.

Usage

From source file:onl.area51.httpd.rest.JsonEntity.java

public JsonEntity(JsonObjectBuilder b) {
    this(b.build());
}

From source file:com.rhcloud.javaee.movieinfo.business.actor.boundry.ActorResourceIT.java

private JsonObject createActor(String firstname, String lastname) {
    JsonObjectBuilder actorBuilder = Json.createObjectBuilder().add(FIRSTNAME, firstname).add(LASTNAME,
            lastname);/*w  w w .jav  a  2s .co  m*/
    return actorBuilder.build();

}

From source file:com.whyjustin.magicmirror.alexa.CompanionServiceInformation.java

/**
 * Serialize this object to JSON./*  w ww. j a v  a 2  s. c o  m*/
 *
 * @return A JSON representation of this object.
 */
public JsonObject toJson() {
    JsonObjectBuilder builder = Json.createObjectBuilder().add(SERVICE_URL, getServiceUrl().toString())
            .add(SSL_CLIENT_KEYSTORE, sslClientKeyStore)
            .add(SSL_CLIENT_KEYSTORE_PASSPHRASE, sslClientKeyStorePassphrase).add(SSL_CA_CERT, sslCaCert);

    return builder.build();
}

From source file:org.acruxsource.sandbox.spring.jmstows.websocket.ChatHandler.java

public void sendMessage(final ChatMessage message) throws IOException {
    logger.info("Sending message to all participants");

    for (WebSocketSession session : sessions) {
        if (session.isOpen()) {
            DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
            JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
            jsonObjectBuilder.add("name", message.getName());
            jsonObjectBuilder.add("message", message.getMessage());
            jsonObjectBuilder.add("date", dateFormat.format(message.getDate()));
            session.sendMessage(new TextMessage(jsonObjectBuilder.build().toString()));
        } else {//ww  w  . j av a 2 s .  c o  m
            sessions.remove(session);
        }
    }
}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

/**
 * Creates a new NetworkConfig instance configured with details supplied in YAML format
 *
 * @param configStream A stream opened on a YAML document containing network configuration details
 * @return A new NetworkConfig instance//from  w  ww  .j a va2s  . c  om
 * @throws InvalidArgumentException
 */
public static NetworkConfig fromYamlStream(InputStream configStream)
        throws InvalidArgumentException, NetworkConfigurationException {

    logger.trace("NetworkConfig.fromYamlStream...");

    // Sanity check
    if (configStream == null) {
        throw new InvalidArgumentException("configStream must be specified");
    }

    Yaml yaml = new Yaml();

    @SuppressWarnings("unchecked")
    Map<String, Object> map = yaml.load(configStream);

    JsonObjectBuilder builder = Json.createObjectBuilder(map);

    JsonObject jsonConfig = builder.build();
    return fromJsonObject(jsonConfig);
}

From source file:co.runrightfast.vertx.core.eventbus.EventBusAddressMessageMapping.java

public JsonObject toJson() {
    final JsonObjectBuilder json = Json.createObjectBuilder().add("address", address).add("requestMessageType",
            requestDefaultInstance.getDescriptorForType().getFullName());
    getResponseDefaultInstance().ifPresent(
            instance -> json.add("responseMessageType", instance.getDescriptorForType().getFullName()));
    return json.build();
}

From source file:servlets.SampleServlet.java

private String getResults(String query, String... params) {
    JsonArrayBuilder productArray = Json.createArrayBuilder();
    String xxx = new String();
    try (Connection conn = Credentials.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }/*from  www  . ja  v  a2s  . c  o m*/
        ResultSet rs = pstmt.executeQuery();
        List list = new LinkedList();
        while (rs.next()) {
            JsonObjectBuilder jsonobj = Json.createObjectBuilder().add("productID", rs.getInt("productID"))
                    .add("Name", rs.getString("Name")).add("Description", rs.getString("Description"))
                    .add("Quantity", rs.getInt("Quantity"));

            xxx = jsonobj.build().toString();
            productArray.add(jsonobj);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SampleServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (params.length == 0) {
        xxx = productArray.build().toString();
    }
    return xxx;
}

From source file:assignment5.ProductServlet.java

/**
 * json format taken from//w  ww .j av  a  2s  .c o  m
 * https://code.google.com/p/json-simple/wiki/EncodingExamples
 *
 * @param query
 * @param params
 * @return
 */
private String getResults(String query, String... params) {
    JsonArrayBuilder productArray = Json.createArrayBuilder();
    String numChanges = new String();
    try (Connection conn = credentials.getConnection()) {
        PreparedStatement pstmt = conn.prepareStatement(query);
        for (int i = 1; i <= params.length; i++) {
            pstmt.setString(i, params[i - 1]);
        }

        ResultSet rs = pstmt.executeQuery();

        while (rs.next()) {

            JsonObjectBuilder jsonobj = Json.createObjectBuilder().add("productID", rs.getInt("productID"))
                    .add("name", rs.getString("name")).add("description", rs.getString("description"))
                    .add("quantity", rs.getInt("quantity"));

            numChanges = jsonobj.build().toString();
            productArray.add(jsonobj);
        }

    } catch (SQLException ex) {
        Logger.getLogger(ProductServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (params.length == 0) {
        numChanges = productArray.build().toString();
    }
    return numChanges;
}

From source file:org.openlmis.converter.CreateObjectTypeConverter.java

@Override
public void convert(JsonObjectBuilder builder, Mapping mapping, String value) {
    List<String> entries = Lists.newArrayList(StringUtils.split(value, ','));
    JsonObjectBuilder inner = Json.createObjectBuilder();

    for (String entry : entries) {
        List<String> keyValue = Lists.newArrayList(StringUtils.split(entry, ':'));

        if (keyValue.size() == 2) {
            inner.add(keyValue.get(0), keyValue.get(1));
        } else {/*from  ww  w .  ja  v  a  2  s.com*/
            logger.warn("Invalid map entry representation: {}. Desired format is \"<key>:<value>\".", entry);
        }
    }

    builder.add(mapping.getTo(), inner.build());
}

From source file:example.SimpleChaincode.java

private String newErrorJson(final Throwable throwable, final String message, final Object... args) {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    if (message != null)
        builder.add("Error", String.format(message, args));
    if (throwable != null) {
        final StringWriter buffer = new StringWriter();
        throwable.printStackTrace(new PrintWriter(buffer));
        builder.add("Stacktrace", buffer.toString());
    }//from ww w  .ja  va  2  s.c  o  m
    return builder.build().toString();
}