Search in sources :

Example 6 with JsonStructure

use of javax.json.JsonStructure in project jcabi-github by jcabi.

the class RtLabels method create.

@Override
public Label create(final String name, final String color) throws IOException {
    final JsonStructure json = Json.createObjectBuilder().add("name", name).add("color", color).build();
    this.request.method(Request.POST).body().set(json).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_CREATED).as(JsonResponse.class).json();
    return new RtLabel(this.entry, this.owner, name);
}
Also used : RestResponse(com.jcabi.http.response.RestResponse) JsonResponse(com.jcabi.http.response.JsonResponse) JsonStructure(javax.json.JsonStructure)

Example 7 with JsonStructure

use of javax.json.JsonStructure in project jcabi-github by jcabi.

the class RtHooks method create.

@Override
public Hook create(final String name, final Map<String, String> config, final boolean active) throws IOException {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    for (final Map.Entry<String, String> entr : config.entrySet()) {
        builder.add(entr.getKey(), entr.getValue());
    }
    final JsonStructure json = Json.createObjectBuilder().add("name", name).add("config", builder).add("active", active).build();
    return this.get(this.request.method(Request.POST).body().set(json).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_CREATED).as(JsonResponse.class).json().readObject().getInt("id"));
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map) JsonStructure(javax.json.JsonStructure)

Example 8 with JsonStructure

use of javax.json.JsonStructure in project jcabi-github by jcabi.

the class RtContents method content.

/**
 * Get the contents of a file or symbolic link in a repository.
 * @param path The content path
 * @param ref The name of the commit/branch/tag.
 * @return Content fetched
 * @throws IOException If there is any I/O problem
 * @see <a href="http://developer.github.com/v3/repos/contents/#get-contents">Get contents</a>
 */
private Content content(final String path, final String ref) throws IOException {
    final String name = "ref";
    RtContent content = null;
    final JsonStructure structure = this.request.method(Request.GET).uri().path(path).queryParam(name, ref).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(JsonResponse.class).json().read();
    if (JsonValue.ValueType.OBJECT.equals(structure.getValueType())) {
        content = new RtContent(this.entry.uri().queryParam(name, ref).back(), this.owner, ((JsonObject) structure).getString("path"));
    }
    return content;
}
Also used : JsonObject(javax.json.JsonObject) JsonStructure(javax.json.JsonStructure)

Example 9 with JsonStructure

use of javax.json.JsonStructure in project jcabi-github by jcabi.

the class RtGists method create.

@Override
public Gist create(final Map<String, String> files, final boolean visible) throws IOException {
    JsonObjectBuilder builder = Json.createObjectBuilder();
    for (final Map.Entry<String, String> file : files.entrySet()) {
        builder = builder.add(file.getKey(), Json.createObjectBuilder().add("content", file.getValue()));
    }
    final JsonStructure json = Json.createObjectBuilder().add("files", builder).add("public", visible).build();
    return this.get(this.request.method(Request.POST).body().set(json).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_CREATED).as(JsonResponse.class).json().readObject().getString("id"));
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map) JsonStructure(javax.json.JsonStructure)

Example 10 with JsonStructure

use of javax.json.JsonStructure in project java-driver by datastax.

the class Jsr353JsonColumn method selectJsonColumn.

// Retrieving JSON objects from a table column
private static void selectJsonColumn(Session session) {
    Statement stmt = select().from("examples", "json_jsr353_column").where(in("id", 1, 2));
    ResultSet rows = session.execute(stmt);
    for (Row row : rows) {
        int id = row.getInt("id");
        // retrieve the JSON payload and convert it to a JsonObject instance
        // note that the codec requires that the type passed to the get() method
        // be always JsonStructure, and not a subclass of it, such as JsonObject,
        // hence the need to downcast to JsonObject manually
        JsonObject user = (JsonObject) row.get("json", JsonStructure.class);
        // it is also possible to retrieve the raw JSON payload
        String json = row.getString("json");
        System.out.printf("Retrieved row:%n" + "id           %d%n" + "user         %s%n" + "user (raw)   %s%n%n", id, user, json);
    }
}
Also used : JsonObject(javax.json.JsonObject) JsonStructure(javax.json.JsonStructure)

Aggregations

JsonStructure (javax.json.JsonStructure)37 JsonObject (javax.json.JsonObject)14 StringReader (java.io.StringReader)7 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 Test (org.junit.Test)5 StringWriter (java.io.StringWriter)4 URL (java.net.URL)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4 IOException (java.io.IOException)3 Map (java.util.Map)3 JsonReader (javax.json.JsonReader)3 JsonString (javax.json.JsonString)3 PipeForward (nl.nn.adapterframework.core.PipeForward)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 JsonArray (javax.json.JsonArray)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 Message (nl.nn.adapterframework.stream.Message)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1