Package net.sf.json

Examples of net.sf.json.JSON


    }
    else if (ERXRestUtils.isPrimitive(object)) {
      response.appendContentString(String.valueOf(object));
    }
    else {
      JSON jsonObject = JSONSerializer.toJSON(object, configWithContext(context));
      String json = (CONSTANTS.SHOULD_PRETTY_PRINT ? jsonObject.toString(CONSTANTS.PRETTY_PRINT_INDENT) : jsonObject.toString());
      response.appendContentString(json);
    }
    response.appendContentString("\n");
  }
View Full Code Here


      // MS: Support direct updating of primitive type keys -- so if you don't want to
      // wrap your request in XML, this will allow it
      // if (!contentStr.trim().startsWith("<")) {
      // contentStr = "<FakeWrapper>" + contentStr.trim() + "</FakeWrapper>";
      // }
      JSON rootJSON = JSONSerializer.toJSON(contentString, configWithContext(context));
      rootRequestNode = createRequestNodeForJSON(null, rootJSON, true, delegate);
    }
    else {
      rootRequestNode = new ERXRestRequestNode(null, true);
      rootRequestNode.setNull(true);
View Full Code Here

            updatingRequest = true;
            String requestBodyAsXml = (String) evt.getNewValue();
            String mediaType = (String) mediaTypeCombo.getSelectedItem();
            if (XmlUtils.seemsToBeXml(requestBodyAsXml) &&
                    seemsToBeJsonContentType(mediaType)) {
                JSON jsonObject = new JsonXmlSerializer().read(requestBodyAsXml);
                contentEditor.setText(jsonObject.toString(3, 0));
            } else {
                contentEditor.setText(requestBodyAsXml);
            }
            updatingRequest = false;
        } else if (evt.getPropertyName().equals("method")) {
View Full Code Here

        } else {
            String content = "<Not JSON content>";

            if (JsonUtil.seemsToBeJsonContentType(me.getResponseHeaders().get("Content-Type", ""))) {
                try {
                    JSON json = new JsonUtil().parseTrimmedText(me.getResponseContent());
                    if (json.isEmpty()) {
                        content = "<Empty JSON content>";
                    } else {
                        content = json.toString(3);
                    }
                } catch (Throwable e) {
                    if (!"Invalid JSON String".equals(e.getMessage())) {
                        e.printStackTrace();
                    } else {
View Full Code Here

        } else {
            String content;

            if (JsonUtil.seemsToBeJsonContentType(httpResponse.getContentType())) {
                try {
                    JSON json = new JsonUtil().parseTrimmedText(httpResponse.getContentAsString());
                    if (json.isEmpty()) {
                        content = "<Empty JSON content>";
                    } else {
                        content = json.toString(3);
                    }
                } catch (JSONException e) {
                    content = httpResponse.getContentAsString();
                }
                contentEditor.setText(content);
View Full Code Here

            if (!updating) {
                updating = true;
                try {
                    String contentAsString = documentContent.getContentAsString();
                    if (seemsToBeJsonContentType(getRequest().getMediaType()) && XmlUtils.seemsToBeXml(contentAsString)) {
                        JSON json = new JsonXmlSerializer().read(contentAsString);
                        processNullsAndEmptyValuesIn(json);
                        request.setRequestContent(json.toString(3, 0));
                    } else {
                        request.setRequestContent(contentAsString);
                    }
                } finally {
                    updating = false;
View Full Code Here

            String requestContent = request.getRequestContent();
            if (!StringUtils.hasContent(requestContent)) {
                return;
            }
            try {
                JSON oldJson = new JsonUtil().parseTrimmedText(requestContent);
                if (!(json instanceof JSONObject) || !(oldJson instanceof JSONObject)) {
                    return;
                }
                overwriteNullValues((JSONObject) json, (JSONObject) oldJson);
            } catch (Exception e) {
View Full Code Here

        serializer = new JsonXmlSerializer();
    }

    @Test
    public void serializesJsonWithVanillaNames() throws Exception {
        JSON parse = new JsonUtil().parseTrimmedText("{ name: 'Barack', surname: 'Obama', profession: 'president'}");

        assertThat(serializer.write(parse), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<o>" +
                "<name type=\"string\">Barack</name>" +
                "<profession type=\"string\">president</profession>" +
                "<surname type=\"string\">Obama</surname>" +
View Full Code Here

                "</o>\r\n"));
    }

    @Test
    public void serializesJsonWithDollarSign() throws Exception {
        JSON parse = new JsonUtil().parseTrimmedText("{ $: 'value' }");

        assertThat(serializer.write(parse), is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<o>" +
                "<_ type=\"string\">value</_>" +
                "</o>\r\n"));
    }
View Full Code Here

    private static final String WHILE_1 = "while(1);";

    public static boolean isValidJson(String value) {
        try {
            JSON json = new JsonSlurper().parseText(value);
            return json != null && !(json instanceof JSONNull);
        } catch (Exception e) {
            return false;
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.json.JSON

Copyright © 2018 www.massapicom. 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.