Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONArray


            if (type == null) {
                type = org.apache.wink.json4j.JSONObject.class;
            }
            try {
                if (type == JSONArray.class || type.isArray() || Collection.class.isAssignableFrom(type)) {
                    return new JSONArray(json);
                }
                return JacksonHelper.MAPPER.readValue(json, org.apache.wink.json4j.JSONObject.class);
            } catch (Exception e) {
                throw new IllegalArgumentException(e);
            }
View Full Code Here


            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

            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

   
    @Test
    public void testEchoWithJSONRPC20BindingBatch() throws Exception {
        JSONObject jsonRequest1 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
        JSONObject jsonRequest2 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC 2.0\"], \"id\": 2}");
        JSONArray batchReq = new JSONArray();
        batchReq.put(jsonRequest1);
        batchReq.put(jsonRequest2);
       
        WebConversation wc = new WebConversation();
        WebRequest request   = new PostMethodWebRequest( SERVICE20_URL, new ByteArrayInputStream(batchReq.toString().getBytes("UTF-8")),"application/json");
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());

        JSONArray jsonResp = new JSONArray(response.getText());
        Assert.assertEquals("echo: Hello JSON-RPC", ((JSONObject) jsonResp.get(0)).getString("result"));
        Assert.assertEquals("echo: Hello JSON-RPC 2.0", ((JSONObject) jsonResp.get(1)).getString("result"));
    }
View Full Code Here

                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> headers,
                              InputStream is) throws IOException, WebApplicationException {
        try {
            return new JSONArray(new InputStreamReader(is, ProviderUtils.getCharset(mediaType)),
                                 false);
        } catch (JSONException e) {
            throw new WebApplicationException(e, 400);
        }
    }
View Full Code Here

            } else if (JSONArray.class.isAssignableFrom(clazz)) {
                ja = (JSONArray)obj;
            } else if (Map.class.isAssignableFrom(clazz)) {
                ja = new JSONObject((Map)obj);
            } else if (Collection.class.isAssignableFrom(clazz)) {
                ja = new JSONArray((Collection)obj);
            } else if (clazz.isArray()) {
                ja = new JSONArray((Object[])obj);
            }
            else {
                //TODO:  Bean introspection time.
                ja = introspectBean(obj,includeSuperclass, new ArrayList());
            }
View Full Code Here

                                } else if (JSONArray.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, val);
                                } else if (Map.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, new JSONObject((Map)val));
                                } else if (Collection.class.isAssignableFrom(vClazz)) {
                                    ja.put(attr, new JSONArray((Collection)obj));
                                } else {
                                    if (val != obj) {
                                        // Try to avoid processing references to itself.
                                        ja.put(attr, introspectBean(val, includeSuperclass, parsedObjects));
                                    }
View Full Code Here

                                                            m = tM;
                                                            if(c != JSONArray.class){
                                                                // Convert it.  Whee.
                                                                List list = (List)c.newInstance();

                                                                JSONArray array = (JSONArray)val;
                                                                for (int j = 0; j < array.length(); j++) {
                                                                    // Convert each type as needed.
                                                                    Object aVal = array.get(j);
                                                                    if(aVal != null){
                                                                        Class aVClazz = aVal.getClass();
                                                                        if(Number.class.isAssignableFrom(aVClazz) ||
                                                                            Boolean.class.isAssignableFrom(aVClazz) ||
                                                                            String.class.isAssignableFrom(aVClazz)) {
View Full Code Here

            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));
            }
        } catch (Exception ex1) {
            ex1.printStackTrace();
            ex = ex1;
View Full Code Here

                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> headers,
                              InputStream is) throws IOException, WebApplicationException {
        try {
            return new JSONArray(new InputStreamReader(is, ProviderUtils.getCharset(mediaType)),
                                 false);
        } catch (JSONException e) {
            throw new WebApplicationException(e, Status.BAD_REQUEST);
        }
    }
View Full Code Here

TOP

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

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.