Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONObject.optJSONArray()


        JSONObject listWithTypeAsJson = json.optJSONObject("keyList");
        Assert.assertNotNull(listWithTypeAsJson);
        Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.TYPE));
        Assert.assertEquals(GraphSONTokens.TYPE_LIST, listWithTypeAsJson.optString(GraphSONTokens.TYPE));
        Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.VALUE));
        JSONArray listAsJSON = listWithTypeAsJson.optJSONArray(GraphSONTokens.VALUE).optJSONObject(0).getJSONArray(GraphSONTokens.VALUE);
        Assert.assertNotNull(listAsJSON);
        Assert.assertEquals(3, listAsJSON.length());

        for (int ix = 0; ix < listAsJSON.length(); ix++) {
            JSONObject valueAsJson = listAsJSON.optJSONObject(ix);
View Full Code Here


  static Collection<ErrorCollection> extractErrors(final int status, final String body) throws JSONException {
    if (body == null) {
      return Collections.emptyList();
    }
    final JSONObject jsonObject = new JSONObject(body);
    final JSONArray issues = jsonObject.optJSONArray("issues");
    final ImmutableList.Builder<ErrorCollection> results = ImmutableList.builder();
    if (issues != null && issues.length() == 0) {
      final JSONArray errors = jsonObject.optJSONArray("errors");
      for (int i = 0; i < errors.length(); i++) {
        final JSONObject currentJsonObject = errors.getJSONObject(i);
View Full Code Here

    }
    final JSONObject jsonObject = new JSONObject(body);
    final JSONArray issues = jsonObject.optJSONArray("issues");
    final ImmutableList.Builder<ErrorCollection> results = ImmutableList.builder();
    if (issues != null && issues.length() == 0) {
      final JSONArray errors = jsonObject.optJSONArray("errors");
      for (int i = 0; i < errors.length(); i++) {
        final JSONObject currentJsonObject = errors.getJSONObject(i);
        results.add(getErrorsFromJson(currentJsonObject.getInt("status"), currentJsonObject
            .optJSONObject("elementErrors")));
      }
View Full Code Here

        assertTrue("Result Query does not contain offset property",jQuery.has("offset"));
        assertTrue("Returned offset is != 0",jQuery.getInt("offset") == 0);
       
        assertSelectedField(jQuery,getDefaultFindQueryField());
       
        JSONArray jConstraints = jQuery.optJSONArray("constraints");
        assertNotNull("Result Query is missing the 'constraints' property",jConstraints);
        assertEquals("Result Query is expected to have a single constraint",
            1, jConstraints.length());
        JSONObject constraint = jConstraints.optJSONObject(0);
        assertNotNull("'constraints' array does not contain a JSONObject but "+jConstraints.get(0),
View Full Code Here

            "}",
            false); //expect BadRequest
        //now execute the test
        RequestExecutor re = executeQuery(test);
        JSONObject jQuery = assertResponseQuery(re.getContent());
        JSONArray jConstraints = jQuery.optJSONArray("constraints");
        assertNotNull("Result Query does not contain the constraints Array",jConstraints);
        assertTrue("Result Query Constraint Array does not contain the expected Constraint",
            jConstraints.length() == 1);
        JSONObject jConstraint = jConstraints.optJSONObject(0);
        assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
View Full Code Here

            "}",
            false); //expect BadRequest
        //now execute the test
        RequestExecutor re = executeQuery(test);
        JSONObject jQuery = assertResponseQuery(re.getContent());
        JSONArray jConstraints = jQuery.optJSONArray("constraints");
        assertNotNull("Result Query does not contain the constraints Array",jConstraints);
        assertTrue("Result Query Constraint Array does not contain the expected Constraint",
            jConstraints.length() == 1);
        JSONObject jConstraint = jConstraints.optJSONObject(0);
        assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
View Full Code Here

            "}",
            false); //expect BadRequest
        //now execute the test
        RequestExecutor re = executeQuery(test);
        JSONObject jQuery = assertResponseQuery(re.getContent());
        JSONArray jConstraints = jQuery.optJSONArray("constraints");
        assertNotNull("Result Query does not contain the constraints Array",jConstraints);
        assertTrue("Result Query Constraint Array does not contain the expected Constraint",
            jConstraints.length() == 1);
        JSONObject jConstraint = jConstraints.optJSONObject(0);
        assertNotNull("Constraint Array does not contain JSONObjects",jConstraint);
View Full Code Here

            //parse the selected fields from the query and add them to the allowed fields
            try {
                JSONObject jQuery = new JSONObject(query);
                //reset the parsed query for better debugging
                this.query = jQuery.toString(4);
                JSONArray selected = jQuery.optJSONArray("selected");
                if(selected != null){
                    for(int i=0;i<selected.length();i++){
                        addAllowedField(selected.getString(i));
                    }
                }
View Full Code Here

  static Collection<ErrorCollection> extractErrors(final int status, final String body) throws JSONException {
    if (body == null) {
      return Collections.emptyList();
    }
    final JSONObject jsonObject = new JSONObject(body);
    final JSONArray issues = jsonObject.optJSONArray("issues");
    final ImmutableList.Builder<ErrorCollection> results = ImmutableList.builder();
    if (issues != null && issues.length() == 0) {
      final JSONArray errors = jsonObject.optJSONArray("errors");
      for (int i = 0; i < errors.length(); i++) {
        final JSONObject currentJsonObject = errors.getJSONObject(i);
View Full Code Here

    }
    final JSONObject jsonObject = new JSONObject(body);
    final JSONArray issues = jsonObject.optJSONArray("issues");
    final ImmutableList.Builder<ErrorCollection> results = ImmutableList.builder();
    if (issues != null && issues.length() == 0) {
      final JSONArray errors = jsonObject.optJSONArray("errors");
      for (int i = 0; i < errors.length(); i++) {
        final JSONObject currentJsonObject = errors.getJSONObject(i);
        results.add(getErrorsFromJson(currentJsonObject.getInt("status"), currentJsonObject
            .optJSONObject("elementErrors")));
      }
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.