Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


            is.close();
            fos.flush();
            fos.close();

            is = fileOut.toURI().toURL().openStream(); //this.getClass().getClassLoader().getResourceAsStream("utf8-array.json");
            JSONObject jObject = new JSONObject(is);
            is.close();
            String expected="\u592a\u548c\u6bbf";
            JSONObject search = (JSONObject)jObject.get("search");
            JSONObject payload = (JSONObject)search.get("payLoad");
            JSONObject ssug = (JSONObject)payload.get("sSug");
            JSONArray items = (JSONArray)ssug.get("item");

            for (int i = 0; i <items.size(); i++) {
                String str = (String)items.get(i);
                assertTrue(expected.equals(str));
            }
View Full Code Here


        try {
            Object[] args = msg.getBody();
            InputStream in = (InputStream) args[0];
            String data = read(in, charset);
            JSONObject jsonPayload = new JSONObject(data);
            msg.setBody(new Object[]{jsonPayload});
        } catch(Exception e) {
            throw new RuntimeException("Unable to parse json paylod: " + msg.getBody().toString());
        }
View Full Code Here

        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper staxHelper = StAXHelper.getInstance(extensionPointRegistry);

        XMLStreamReader reader = staxHelper.createXMLStreamReader(new StringReader(IPO_XML));
        XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(extensionPointRegistry);
        JSONObject json = (JSONObject)t1.transform(reader, null);
        Assert.assertNotNull(json);

        // Cannot round-trip as we hit a bug in Jettison: http://jira.codehaus.org/browse/JETTISON-93
        /*
        JSON2XMLStreamReader t2 = new JSON2XMLStreamReader();
View Full Code Here

    public void testJSON2XML() throws Exception {
        ExtensionPointRegistry extensionPointRegistry = new DefaultExtensionPointRegistry();
        StAXHelper helper = StAXHelper.getInstance(extensionPointRegistry);

        JSON2XMLStreamReader t2 = new JSON2XMLStreamReader();
        XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null);
        StringWriter sw = new StringWriter();
        XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
        helper.save(reader2, streamWriter);
        Assert.assertTrue(sw.toString()
            .contains("<xsl:root xmlns:xsl=\"http://foo.com\"><data>my json string</data></xsl:root>"));
View Full Code Here

    public void testJSON2OMElement() throws Exception {
        JSON2OMElement t1 = new JSON2OMElement();
        TransformationContext context = new TransformationContextImpl();
        DataType dt = new DataTypeImpl(Object.class, new XMLType(new QName("http://foo.com", "root"), null));
        context.setTargetDataType(dt);
        OMElement element = t1.transform(new JSONObject(JSON_STR), context);
        StringWriter writer = new StringWriter();
        element.serialize(writer);
        // System.out.println(writer.toString());
    }
View Full Code Here

    @Test
    public void testString2JSON() throws Exception {
        String json = "{\"name\":\"John\",\"age\":25}";
        String2JSON t1 = new String2JSON();
        JSONObject jsonObject = (JSONObject)t1.transform(json, null);
        Assert.assertEquals(jsonObject.getString("name"), "John");
        Assert.assertEquals(jsonObject.getInt("age"), 25);
        JSON2String t2 = new JSON2String();
        String str = t2.transform(jsonObject, null);
        Assert.assertTrue(str.contains("\"name\":\"John\""));
        Assert.assertTrue(str.contains("\"age\":25"));
    }
View Full Code Here

        Assert.assertTrue(validateJsonResponse(GET_UPDATED_RESPONSE,response.getText()));
    }


    private boolean validateJsonResponse(String expected, String actual) throws JSONException {
        JSONObject jsonExpected = new JSONObject(expected);
        JSONObject jsonActual = new JSONObject(actual);

        if(jsonExpected.getJSONArray("items").length() != jsonActual.getJSONArray("items").length()) {
            return false;
        }

        return true;
View Full Code Here

        WebConversation wc = new WebConversation();
        WebRequest request = new GetMethodWebRequest(SMD_URL);
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());
        JSONObject smd = new JSONObject(response.getText());
        Assert.assertEquals(Echo.class.getMethods().length, smd.getJSONArray("methods").length());

        // System.out.println(">>>SMD:\n" + response.getText());
    }
View Full Code Here

    public static String interfaceToSmd(Class<?> klazz, String serviceUrl) {
        try {
            String name = klazz.getSimpleName();
            Method[] methods = klazz.getMethods();

            JSONObject smd = new JSONObject();
            smd.put("SMDVersion", ".1");
            smd.put("objectName", name);
            smd.put("serviceType", "JSON-RPC");
            smd.put("serviceURL", serviceUrl);

            JSONArray services = new JSONArray();
            for (int i = 0; i < methods.length; i++) {
                JSONObject service = new JSONObject();
                Class<?>[] params = methods[i].getParameterTypes();
                JSONArray paramArray = new JSONArray();
                for (int j = 0; j < params.length; j++) {
                    JSONObject param = new JSONObject();
                    param.put("name", "param" + j);
                    param.put("type", getJSONType(params[j]));
                    paramArray.put(param);
                }
                service.put("name", methods[i].getName());
                service.put("parameters", paramArray);
                services.put(service);
View Full Code Here

    public static String interfaceToSmd20(Class<?> klazz, String serviceUrl) {
        try {
            String name = klazz.getSimpleName();
            Method[] methods = klazz.getMethods();

            JSONObject smd = new JSONObject();
            smd.put("SMDVersion", "2.0");
            smd.put("transport", "POST");
            smd.put("envelope", "JSON-RPC-1.0");
            smd.put("target", serviceUrl);
            smd.put("id", klazz.getName());
            smd.put("description", "JSON-RPC service provided by Tuscany: " + name);

            JSONObject services = new JSONObject();
            for (int i = 0; i < methods.length; i++) {
                JSONObject service = new JSONObject();
                Class<?>[] params = methods[i].getParameterTypes();
                JSONArray paramArray = new JSONArray();
                for (int j = 0; j < params.length; j++) {
                    JSONObject param = new JSONObject();
                    param.put("name", "param" + j);
                    param.put("type", getJSONType(params[j]));
                    paramArray.put(param);
                }
                service.put("parameters", paramArray);
                services.put(methods[i].getName(), service);
            }
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.JSONObject

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.