Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONArtifact


     * @return An instance of the JSONArtifact that best represents the data in this JavaBean
     * @throws IllegalArgumentException Thrown if input type is a String, Number, Boolean, etc.
     * @throws JSONException Thrown if a JSON conversion error occurs.
     */
    public static JSONArtifact toJson(Object obj, boolean includeSuperclass) throws IllegalArgumentException, JSONException {
        JSONArtifact ja = null;

        if (obj != null) {
            Class clazz = obj.getClass();
            if (String.class  == clazz) {
                throw new IllegalArgumentException("Class was String type, not a Javabean.");
View Full Code Here


     * @return An instance of the JSONArtifact that best represents the data in this JavaBean
     * @throws IllegalArgumentException Thrown if input type is a String, Number, Boolean, etc.
     * @throws JSONException Thrown if a JSON conversion error occurs.
     */
    public static JSONArtifact toJson(Object obj, boolean includeSuperclass) throws IllegalArgumentException, JSONException {
        JSONArtifact ja = null;

        if (obj != null) {
            Class clazz = obj.getClass();
            if (String.class  == clazz) {
                throw new IllegalArgumentException("Class was String type, not a Javabean.");
View Full Code Here

        Exception ex = null;
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("simple.xml");

        try {
            String json = XML.toJson(is);
            JSONArtifact jsonA = JSON.parse(json);

            assertTrue(jsonA instanceof JSONObject);

            StringWriter strWriter = new StringWriter();
            jsonA.write(strWriter);
            System.out.println("JSON compacted text (jObject):");
            System.out.println(strWriter.toString());
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

     */
    public void testJSONGenericArrayParse() {
        Exception ex = null;
        try {
            String json = "[ \"foo\", true, 1, null ]";
            JSONArtifact jsonA = JSON.parse(json);

            assertTrue(jsonA instanceof JSONArray);

            StringWriter strWriter = new StringWriter();
            jsonA.write(strWriter);
            System.out.println("JSON compacted text (jArray):");
            System.out.println(strWriter.toString());
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

     */
    public void testJSONGenericObjectParse_startingWhitespace() {
        Exception ex = null;
        try {
            String json = "\t\t\t    \b\n\f\r   \t\t  { \"foo\": true, \"bar\": 1, \"noVal\": null }";
            JSONArtifact jsonA = JSON.parse(json);

            assertTrue(jsonA instanceof JSONObject);

            StringWriter strWriter = new StringWriter();
            jsonA.write(strWriter);
            System.out.println("JSON compacted text (jObject):");
            System.out.println(strWriter.toString());
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

     */
    public void testJSONGenericArrayParse_startingWhitespace() {
        Exception ex = null;
        try {
            String json = "\t\t\t    \b\n\f\r   \t\t  [ \"foo\", true, 1, null ]";
            JSONArtifact jsonA = JSON.parse(json);

            assertTrue(jsonA instanceof JSONArray);

            StringWriter strWriter = new StringWriter();
            jsonA.write(strWriter);
            System.out.println("JSON compacted text (jArray):");
            System.out.println(strWriter.toString());
        } catch (Exception ex1) {
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

     */
    public void test_Date_WithSuper() {
        Exception ex = null;
        try{
            Date date = new Date();
            JSONArtifact ja = BeanSerializer.toJson(date, true);
            assertTrue(((JSONObject)ja).get("class").equals("java.util.Date"));
            System.out.println(ja.write(3));
        } catch (Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

     */
    public void test_Date_WithOutSuper() {
        Exception ex = null;
        try{
            Date date = new Date();
            JSONArtifact ja = BeanSerializer.toJson(date, false);
            assertTrue(((JSONObject)ja).opt("class") == null);
            System.out.println(ja.write(3));
        } catch (Exception ex1){
            ex = ex1;
            ex.printStackTrace();
        }
        assertTrue(ex == null);
View Full Code Here

    public void test_Date_RebuildWithOutSuper() {
        Exception ex = null;
        try{
            Date date = new Date();
            JSONArtifact ja = BeanSerializer.toJson(date, false);
            assertTrue(((JSONObject)ja).opt("class") == null);
            System.out.println(ja.write(3));
            Date date2 = (Date)BeanSerializer.fromJson((JSONObject)ja);
            System.out.println("Date: " + date2.toString());
        } catch (Exception ex1){
            ex = ex1;
            ex.printStackTrace();
View Full Code Here

TOP

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

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.