Package net.sf.json

Examples of net.sf.json.JSON


        log.debug("sendContent: " + encodedUrl);
        JsonConfig cfg = new JsonConfig();
        cfg.setIgnoreTransientFields(true);
        cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

        JSON json;
        Writer writer = new PrintWriter(out);
        String[] arr;
        if (propertyBuilder == null) {
            if (wrappedResource instanceof CollectionResource) {
                List<? extends Resource> children = ((CollectionResource) wrappedResource).getChildren();
                json = JSONSerializer.toJSON(toSimpleList(children), cfg);
            } else {
                json = JSONSerializer.toJSON(toSimple(wrappedResource), cfg);
            }
        } else {
            // use propfind handler
            String sFields = params.get("fields");
            Set<QName> fields = new HashSet<QName>();
            Map<QName, String> aliases = new HashMap<QName, String>();
            if (sFields != null && sFields.length() > 0) {
                arr = sFields.split(",");
                for (String s : arr) {
                    parseField(s, fields, aliases);
                }
            }

            String sDepth = params.get("depth");
            int depth = 1;
            if (sDepth != null && sDepth.trim().length() > 0) {
                depth = Integer.parseInt(sDepth);
            }

            String href = encodedUrl.replace("/_DAV/PROPFIND", "");
            log.debug("prop builder: " + propertyBuilder.getClass());
            ParseResult parseResult = new ParseResult(false, fields);
            List<PropFindResponse> props = propertyBuilder.buildProperties(wrappedResource, depth, parseResult, href);

            String where = params.get("where");
            filterResults(props, where);

            List<Map<String, Object>> list = helper.toMap(props, aliases);
            json = JSONSerializer.toJSON(list, cfg);
        }
        json.write(writer);
        writer.flush();
    }
View Full Code Here


        log.debug( "errors size: " + errors.size());

        FieldError[] arr = new FieldError[errors.size()];
        arr = errors.toArray( arr );
        Writer writer = new PrintWriter( out );
        JSON json = JSONSerializer.toJSON( arr, cfg );
        json.write( writer );
        writer.flush();
    }
View Full Code Here

        } else {
            arr = new NewFile[0];
        }
        arr = newFiles.toArray(arr);
        Writer writer = new PrintWriter(out);
        JSON json = JSONSerializer.toJSON(arr, cfg);
        json.write(writer);
        writer.flush();
    }
View Full Code Here

            throw new IllegalArgumentException( "SecureResource may not be null");
        }
    }

    public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException {
        JSON json = JSONSerializer.toJSON(result);
        PrintWriter writer = new PrintWriter(out);
        json.write(writer);
        writer.flush();
    }
View Full Code Here

        if (xml == null) {
            xml = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, graph);
            streamTreatment = false;
        }

        JSON json;
        // perform the marshaling to JSON
        if (streamTreatment) {
            json = serializer.readFromStream((InputStream) xml);
        } else {
            json = serializer.read((String) xml);
        }

        OutputStreamWriter osw = new OutputStreamWriter(stream);
        json.write(osw);
        osw.flush();

    }
View Full Code Here

     * Convert from JSON to XML
     */
    @Override
    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
        Object inBody = exchange.getIn().getBody();
        JSON toConvert;
        // if the incoming object is already a JSON object, process as-is,
        // otherwise parse it as a String
        if (inBody instanceof JSON) {
            toConvert = (JSON) inBody;
        } else {
View Full Code Here

    @Test
    public void testUnmarshalJSONObject() throws Exception {
        InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.json");
        String in = context.getTypeConverter().convertTo(String.class, inStream);
        JSON json = JSONSerializer.toJSON(in);

        MockEndpoint mockXML = getMockEndpoint("mock:xml");
        mockXML.expectedMessageCount(1);
        mockXML.message(0).body().isInstanceOf(String.class);
View Full Code Here

        if (xml == null) {
            xml = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, graph);
            streamTreatment = false;
        }

        JSON json;
        // perform the marshaling to JSON
        if (streamTreatment) {
            json = serializer.readFromStream((InputStream) xml);
        } else {
            json = serializer.read((String) xml);
        }

        OutputStreamWriter osw = new OutputStreamWriter(stream);
        json.write(osw);
        osw.flush();

    }
View Full Code Here

     * Convert from JSON to XML
     */
    @Override
    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
        Object inBody = exchange.getIn().getBody();
        JSON toConvert;
        // if the incoming object is already a JSON object, process as-is,
        // otherwise parse it as a String
        if (inBody instanceof JSON) {
            toConvert = (JSON) inBody;
        } else {
View Full Code Here

        if (xml == null) {
            xml = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, exchange, graph);
            streamTreatment = false;
        }

        JSON json;
        // perform the marshaling to JSON
        if (streamTreatment) {
            json = serializer.readFromStream((InputStream) xml);
        } else {
            json = serializer.read((String) xml);
        }
        // don't return the default setting here
        String encoding = IOHelper.getCharsetName(exchange, false);
        if (encoding == null) {
            encoding = getEncoding();
        }
        OutputStreamWriter osw = null;
        if (encoding != null) {
            osw = new OutputStreamWriter(stream, encoding);
        } else {
            osw = new OutputStreamWriter(stream);
        }
        json.write(osw);
        osw.flush();

    }
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.