Package org.apache.pivot.json

Examples of org.apache.pivot.json.JSONSerializer


     * @throws IOException
     * @throws SerializationException
     */
    @Test
    public void testDictionary() throws IOException, SerializationException {
        JSONSerializer dictionarySerializer = new JSONSerializer(SampleBean2DictionarySubclass.class);

        SampleBean2Dictionary dictionary =
            (SampleBean2Dictionary)dictionarySerializer.readObject(new StringReader("{foo: {a:1, b:2, c:'3'}}"));

        assertTrue(JSON.get(dictionary, "foo") instanceof SampleBean2);
        assertEquals(JSON.get(dictionary, "foo.c"), "3");
    }
View Full Code Here


     * @throws SerializationException
     */
    @Test
    @SuppressWarnings("unchecked")
    public void testBean() throws IOException, SerializationException {
        JSONSerializer mapSerializer = new JSONSerializer();
        Map<String, Object> map =
            (Map<String, Object>)mapSerializer.readObject(getClass().getResourceAsStream("map.json"));

        JSONSerializer beanSerializer = new JSONSerializer(SampleBean1.class);
        SampleBean1 typedMap =
            (SampleBean1)beanSerializer.readObject(getClass().getResourceAsStream("map.json"));

        assertEquals(typedMap.getA(), JSON.get(map, "a"));
        assertEquals(typedMap.getB(), JSON.get(map, "b"));
        assertEquals(typedMap.getC(), JSON.get(map, "c"));
        assertEquals(typedMap.getD(), JSON.get(map, "d"));
View Full Code Here

        }
    }

    @Override
    protected Serializer<?> createSerializer(Method method, Path path) throws QueryException {
        return new JSONSerializer(Expense.class);
    }
View Full Code Here

        });

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

                try {
                    form.load(serializer.readObject(inputStream));
                    sourceLabel.setText("JSON");
                } catch(Exception exception) {
                    System.err.println(exception);
                }
View Full Code Here

    public void setListData(URL listData) {
        if (listData == null) {
            throw new IllegalArgumentException("listData is null.");
        }

        JSONSerializer jsonSerializer = new JSONSerializer();

        try {
            setListData((List<?>)jsonSerializer.readObject(listData.openStream()));
        } catch (SerializationException exception) {
            throw new IllegalArgumentException(exception);
        } catch (IOException exception) {
            throw new IllegalArgumentException(exception);
        }
View Full Code Here

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream(name);

        if (inputStream != null) {
            JSONSerializer serializer = new JSONSerializer(charset);

            try {
                resourceMap = (Map<String, Object>)serializer.readObject(inputStream);
            } finally {
                inputStream.close();
            }
        }
View Full Code Here

        window.setTitle(WINDOW_TITLE);
        window.open(display);
        window.requestFocus();

        if (System.in.available() > 0) {
            JSONSerializer jsonSerializer = new JSONSerializer();
            try {
                setValue(jsonSerializer.readObject(System.in));
            } catch (Exception exception) {
                // No-op
            }
        }
    }
View Full Code Here

        Manifest clipboardContent = Clipboard.getContent();

        if (clipboardContent != null
            && clipboardContent.containsText()) {
            String json = null;
            JSONSerializer jsonSerializer = new JSONSerializer();
            try {
                json = clipboardContent.getText();
                setValue(jsonSerializer.readObject(new StringReader(json)));
            } catch (Exception exception) {
                Prompt.prompt(exception.getMessage(), window);
            }

            window.setTitle(WINDOW_TITLE);
View Full Code Here

        try {
            FileList fileList = dragContent.getFileList();
            if (fileList.getLength() == 1) {
                File file = fileList.get(0);

                JSONSerializer jsonSerializer = new JSONSerializer();
                FileInputStream fileInputStream = null;
                try {
                    try {
                        fileInputStream = new FileInputStream(file);
                        setValue(jsonSerializer.readObject(fileInputStream));
                    } finally {
                        if (fileInputStream != null) {
                            fileInputStream.close();
                        }
                    }
View Full Code Here

            throw new QueryException(Query.Status.NOT_FOUND);
        }

        Object value;
        try {
            JSONSerializer jsonSerializer = new JSONSerializer();
            value = jsonSerializer.readObject(new FileInputStream(file));
        } catch (IOException exception) {
            throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
        } catch (SerializationException exception) {
            throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
        }
View Full Code Here

TOP

Related Classes of org.apache.pivot.json.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.