Package javax.json

Examples of javax.json.JsonObject.containsKey()


        Response response = getResource(resourceURL, APPLICATION_JSON_TYPE);

        JsonObject content = response.readEntity(JsonObject.class);
        System.out.println(content);

        assertTrue(content.containsKey("result"));
        assertEquals("Hello World!", content.getString("result"));
    }

    /**
     * The purpose of this method is to run the external REST request.
View Full Code Here


         * @throws IOException If it fails
         */
        @NotNull(message = "Name is never NULL")
        public String name() throws IOException {
            final JsonObject json = this.json();
            if (!json.containsKey("name")) {
                throw new IllegalStateException(
                    String.format(
                        // @checkstyle LineLength (1 line)
                        "User %s doesn't have a name specified in his/her Github account; use #hasName() first.",
                        this.login()
View Full Code Here

    @NotNull(message = "JSON is never NULL")
    public JsonObject json() throws IOException {
        final JsonObject json = new RtJson(this.entry)
            .fetch()
            .getJsonObject("resources");
        if (!json.containsKey(this.res)) {
            throw new IllegalStateException(
                String.format(
                    "'%s' is absent in JSON: %s", this.res, json
                )
            );
View Full Code Here

    public <T> T value(
        @NotNull(message = "name can't be NULL") final String name,
        @NotNull(message = "type can't be NULL") final Class<T> type
    ) throws IOException {
        final JsonObject json = this.json();
        if (!json.containsKey(name)) {
            throw new IllegalStateException(
                String.format(
                    "'%s' is absent in JSON: %s", name, json
                )
            );
View Full Code Here

      String json = target.request().post(Entity.json("{ \"name\" : \"Bill\" }"), String.class);
      System.out.println(json);

      JsonObject obj = Json.createObjectBuilder().add("name", "Bill").build();
      obj = target.request().post(Entity.json(obj), JsonObject.class);
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");

   }

   @Test
View Full Code Here

      JsonArray array = Json.createArrayBuilder().add(Json.createObjectBuilder().add("name", "Bill").build())
                                                 .add(Json.createObjectBuilder().add("name", "Monica").build()).build();
      array = target.request().post(Entity.json(array), JsonArray.class);
      Assert.assertEquals(2, array.size());
      JsonObject obj = array.getJsonObject(0);
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");
      obj = array.getJsonObject(1);
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Monica");
View Full Code Here

      Assert.assertEquals(2, array.size());
      JsonObject obj = array.getJsonObject(0);
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");
      obj = array.getJsonObject(1);
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Monica");

   }

   @Test
View Full Code Here

      System.out.println(json);

      JsonObject obj = Json.createObjectBuilder().add("name", "Bill").build();
      JsonStructure structure = target.request().post(Entity.json(obj), JsonStructure.class);
      obj = (JsonObject)structure;
      Assert.assertTrue(obj.containsKey("name"));
      Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");

   }

View Full Code Here

      @Consumes("application/json")
      public JsonArray array(JsonArray array)
      {
         Assert.assertEquals(2, array.size());
         JsonObject obj = array.getJsonObject(0);
         Assert.assertTrue(obj.containsKey("name"));
         Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");
         obj = array.getJsonObject(1);
         Assert.assertTrue(obj.containsKey("name"));
         Assert.assertEquals(obj.getJsonString("name").getString(), "Monica");
         return array;
View Full Code Here

         Assert.assertEquals(2, array.size());
         JsonObject obj = array.getJsonObject(0);
         Assert.assertTrue(obj.containsKey("name"));
         Assert.assertEquals(obj.getJsonString("name").getString(), "Bill");
         obj = array.getJsonObject(1);
         Assert.assertTrue(obj.containsKey("name"));
         Assert.assertEquals(obj.getJsonString("name").getString(), "Monica");
         return array;
      }

      @Path("object")
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.