Package pivot.serialization

Examples of pivot.serialization.JSONSerializer


        InputStream in = getClass().getClassLoader().getResourceAsStream(name);
        if (in == null) {
            return null;
        }

        JSONSerializer serializer = new JSONSerializer(charset);
        Map<String, Object> resourceMap = null;
        try {
            resourceMap = (Map<String, Object>) serializer.readObject(in);
        } finally {
            in.close();
        }

        return resourceMap;
View Full Code Here


        HashMap<String, Object> c = new HashMap<String, Object>();
        c.put("d", "Hello World");
        a.put("c", c);

        StringWriter writer = new StringWriter();
        JSONSerializer jsonSerializer = new JSONSerializer();
        try {
            jsonSerializer.writeObject(a, writer);
        } catch(Exception exception) {
            System.out.println(exception);
        }

        System.out.println("Output: " + writer);
View Full Code Here

        System.out.println("Output: " + writer);
    }

    public static void test1() {
        JSONSerializer jsonSerializer = new JSONSerializer();

        for (int i = 0, n = testStrings.length; i < n; i++) {
            try {
                System.out.println("Input: " + testStrings[i]);
                Object object = jsonSerializer.readObject(new StringReader(testStrings[i]));
                System.out.println("Object: " + object);
                StringWriter writer = new StringWriter();
                jsonSerializer.writeObject(object, writer);

                System.out.println("Output: " + writer);
            } catch(Exception exception) {
                System.out.println(exception);
            }
View Full Code Here

        testList("[[0, 1, 2], [3, 4, 5]]", "[1][]");
        testList("[[0, 1, 2], [3, 4, 5]]", "[1][0][0]");
    }

    public static void test3() {
        JSONSerializer serializer = new JSONSerializer("ISO-8859-1");
        InputStream inputStream = JSONSerializerTest.class.getResourceAsStream("json_serializer_test.json");

        Object root = null;
        try {
            root = serializer.readObject(inputStream);
        } catch(Exception exception) {
            System.out.println(exception);
        }

        if (root != null) {
            System.out.println(JSONSerializer.getString(root, "foo"));
            System.out.println(JSONSerializer.getString(root, "bar"));
        }

        try {
            serializer.writeObject(root, System.out);
        } catch(Exception exception) {
            System.out.println(exception);
        }
    }
View Full Code Here

            System.out.println(exception);
        }
    }

    private static void testList(String list, String path) {
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            jsonSerializer.writeObject(JSONSerializer.get(JSONSerializer.parseList(list), path),
                System.out);
            System.out.println();
        } catch(Exception exception) {
            System.out.println(exception);
        }
View Full Code Here

            System.out.println(exception);
        }
    }

    private static void testMap(String map, String path) {
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            jsonSerializer.writeObject(JSONSerializer.get(JSONSerializer.parseMap(map), path),
                System.out);
            System.out.println();
        } catch(Exception exception) {
            System.out.println(exception);
        }
View Full Code Here

        System.out.println("a['h'] exists: " + JSONSerializer.containsKey(root, "a['h']"));
    }

    public static void test5() {
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            jsonSerializer.writeObject(JSONSerializer.parse("// This is a comment\n\n['a', /*FOO*/ //dfsdf\n 'b' // FSKJHJKDSF\r /*ASDKHASD*/]"), System.out);
        } catch(Exception exception) {
            System.err.println(exception);
        }
    }
View Full Code Here

        });

        loadJSONButton.getButtonPressListeners().add(new ButtonPressListener() {
          @SuppressWarnings("unchecked")
          public void buttonPressed(Button button) {
            JSONSerializer serializer = new JSONSerializer();
            InputStream inputStream = getClass().getResourceAsStream("contact.json");

            try {
                form.load((Map<String, Object>)serializer.readObject(inputStream));
                sourceLabel.setText("JSON");
            } catch(Exception exception) {
              System.out.println(exception);
            }
View Full Code Here

        try {
            InputStream inputStream = location.openStream();

            try {
                JSONSerializer serializer = new JSONSerializer();
                Map<String, ?> properties = (Map<String, ?>)serializer.readObject(inputStream);

                font = Font.decode((String)properties.get("font"));

                List<String> colorCodes = (List<String>)properties.get("colors");
                colors = new Color[colorCodes.getLength() * 3];
 
View Full Code Here

        Map<String, Object> cachedStyles =
            (Map<String, Object>)ApplicationContext.getResourceCache().get(styles);

        if (cachedStyles == null) {
            JSONSerializer jsonSerializer = new JSONSerializer();
            cachedStyles =
                (Map<String, Object>)jsonSerializer.readObject(styles.openStream());

            ApplicationContext.getResourceCache().put(styles, cachedStyles);
        }

        setStyles(cachedStyles);
View Full Code Here

TOP

Related Classes of pivot.serialization.JSONSerializer

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.