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


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        ServletInputStream inputStream = request.getInputStream();
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            Object value = jsonSerializer.readObject(inputStream);
            jsonSerializer.writeObject(value, System.out);
            response.setStatus(201);
            response.setHeader("Location", request.getPathInfo() +"#101");
        } catch(SerializationException exception) {
            throw new ServletException(exception);
        }
View Full Code Here

    @Override
    protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        ServletInputStream inputStream = request.getInputStream();
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            Object value = jsonSerializer.readObject(inputStream);
            jsonSerializer.writeObject(value, System.out);
            response.setStatus(200);
        } catch(SerializationException exception) {
            throw new ServletException(exception);
        }
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.getValue(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.getValue(JSONSerializer.parseMap(map), path),
                System.out);
            System.out.println();
        } catch(Exception exception) {
            System.out.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

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        ServletInputStream inputStream = request.getInputStream();
        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            Object value = jsonSerializer.readObject(inputStream);
            jsonSerializer.writeObject(value, System.out);
            response.setStatus(201);
            response.setHeader("Location", request.getPathInfo() +"#101");
        } catch(SerializationException exception) {
            throw new ServletException(exception);
        }
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.