Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


                                                    }
                                                }
                                            }
                                        } else if (JSONObject.class.isAssignableFrom(vClazz)) {
                                            // Handle determining a map type to set, if there is one.
                                            JSONObject jObj = (JSONObject)val;
                                            Class vC = val.getClass();
                                            if(jObj.get("_classname") != null && "JavaClass".equals(jObj.get("_type"))){
                                                val = fromJson(jObj);
                                                vC = val.getClass();
                                            }

                                            // Handle locating a boolean method.
View Full Code Here


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

            is = fileOut.toURL().openStream();// this.getClass().getClassLoader().getResourceAsStream("json_output/utf8-lowerchar.json");
            JSONObject jObject = new JSONObject(is);
            is.close();
            String str = (String)jObject.get("hi");
            String expected="\u00C5\u00C5\u00C5\u00C5";
            //Compare this to the string with unicode \u00C5 in it.
            assertTrue(expected.equals(str));

        } catch (Exception ex1) {
View Full Code Here

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

            is = fileOut.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

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

                                null,
                                MediaType.APPLICATION_JSON_TYPE,
                                null,
                                os);
        InputStream is = new ByteArrayInputStream(os.toByteArray());
        JSONObject jsonObject =
            json4jObjectProvider.readFrom(JSONObject.class,
                                          JSONObject.class,
                                          null,
                                          MediaType.APPLICATION_JSON_TYPE,
                                          null,
                                          is);
        assertEquals("Joe", jsonObject.get("first"));
        assertEquals("Shmoe", jsonObject.get("last"));
        assertEquals(100, jsonObject.get("age"));
    }
View Full Code Here

        assertEquals("Shmoe", jsonObject.get("last"));
        assertEquals(100, jsonObject.get("age"));
    }

    public void testPOJOInteroperabilityJSON4JToJackson() throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("first", "Joe");
        jsonObject.put("last", "Shmoe");
        jsonObject.put("age", 100);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        json4jObjectProvider.writeTo(jsonObject,
                                     JSONObject.class,
                                     JSONObject.class,
                                     null,
                                     MediaType.APPLICATION_JSON_TYPE,
                                     null,
                                     os);
        InputStream is = new ByteArrayInputStream(os.toByteArray());
        PersonPOJO p =
            (PersonPOJO)jacksonProvider.readFrom(Object.class,
                                                 PersonPOJO.class,
                                                 null,
                                                 MediaType.APPLICATION_JSON_TYPE,
                                                 null,
                                                 is);
        assertEquals("Joe", p.getFirst());
        assertEquals("Shmoe", p.getLast());
        assertEquals(100, p.getAge());

        jsonObject = new JSONObject();
        jsonObject.put("first", "Joe");
        jsonObject.put("last", "Shmoe");
        jsonObject.put("age", "100"); // this is the only change to see if an
        // integer as a String works
        os = new ByteArrayOutputStream();
        json4jObjectProvider.writeTo(jsonObject,
                                     JSONObject.class,
                                     JSONObject.class,
View Full Code Here

        assertEquals(200, response.getStatus());
        assertTrue(JSONUtils
            .equals(new org.json.JSONObject(
                                            "{\"person\":{\"name\":\"myName\", \"desc\":\"myDescription\", \"age\":\"100\"}}"),
                    new org.json.JSONObject(response.getContentAsString())));
        JSONObject result = new JSONObject(new ByteArrayInputStream(response.getContentAsByteArray()));
        JSONObject person = (JSONObject)result.get("person");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", person.get("name"));
        jsonObject.put("desc", person.get("desc"));
        jsonObject.put("age", person.get("age"));
        Person p =
            (Person)jacksonProvider.readFrom(Object.class,
                                             Person.class,
                                             null,
                                             MediaType.APPLICATION_JSON_TYPE,
                                             null,
                                             new ByteArrayInputStream(jsonObject.toString()
                                                 .getBytes()));
        assertEquals("myName", p.getName());
        assertEquals("myDescription", p.getDesc());
        assertEquals(100, p.getAge());
    }
View Full Code Here

        assertEquals(46, ((JSONObject)jsonArray.get(1)).get("age"));
    }

    public void testArrayInteroperabilityJSON4JToJackson() throws Exception {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject1.put("first", "firstName");
        jsonObject1.put("last", "lastName");
        jsonObject1.put("age", 45);
        jsonObject2.put("first", "firstName2");
        jsonObject2.put("last", "lastName2");
        jsonObject2.put("age", 46);
        jsonArray.add(jsonObject1);
        jsonArray.add(jsonObject2);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        json4jArrayProvider.writeTo(jsonArray,
                                    JSONArray.class,
View Full Code Here

    private static final String JSON_ARRAY = "[" + JSON + ", {\"test\":\"ing\"}]";

    private void compairJsonContent(final String expected, final String actual)
        throws JSONException {
        JSONObject result = new JSONObject(actual);
        JSONObject want = new JSONObject(expected);
        assertEquals(result.toString(), want.toString());
    }
View Full Code Here

                                                        "application/json",
                                                        MediaType.APPLICATION_JSON,
                                                        JSON.getBytes());
        MockHttpServletResponse response = invoke(request);
        assertEquals(200, response.getStatus());
        JSONObject result = new JSONObject(response.getContentAsString());
        JSONObject want = new JSONObject(JSON);
        want.put("foo", "bar");
        assertEquals(want.toString(), result.toString());
    }
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.