Package cc.plural.jsonij

Examples of cc.plural.jsonij.Value


    @Test
    public void testMarshalJSONNumericBigInteger() throws JSONMarshalerException, IOException, ParserException {
        System.out.println("testMarshalJSONNumericBigInteger");

        String inputJSONDocument = "12345678900987654321123456789009876543211234567890098765432112345678900987654321";       
        Value inputValue = JSON.parseValue(inputJSONDocument);
        System.out.println(String.format("InputJSON: %s", inputValue.toJSON()));
        Object marshal = JSONMarshaler.marshalJSON(inputValue, BigInteger.class);
        System.out.println(String.format("MarshaledObjectToString: %s", marshal));
        Value outputValue = JSONMarshaler.marshalObjectToValue(marshal);
        System.out.println(String.format("OutputJSON: %s", outputValue));

        assertNotNull(marshal);
        assertEquals(inputValue, outputValue);
    }
View Full Code Here


    @Test
    public void testMarshalJSONNumericBigDecimal() throws JSONMarshalerException, IOException, ParserException {
        System.out.println("testMarshalJSONNumericBigDecimal");

        String inputJSONDocument = "12345678900987654321123456789009876543211234567890098765432112345678900987654321.12345678900987654321123456789009876543211234567890098765432112345678900987654321123456789009";       
        Value inputValue = JSON.parseValue(inputJSONDocument);
        System.out.println(String.format("InputJSON: %s", inputValue.toJSON()));
        Object marshal = JSONMarshaler.marshalJSON(inputValue, BigDecimal.class);
        System.out.println(String.format("MarshaledObjectToString: %s", marshal));
        Value outputValue = JSONMarshaler.marshalObjectToValue(marshal);
        System.out.println(String.format("OutputJSON: %s", outputValue));

        assertNotNull(marshal);
        assertEquals(inputValue, outputValue);
    }
View Full Code Here

        System.out.println(json.getRoot().getValueType() + "(" + json.getRoot().nestedSize() + "): " + json.getRoot().toJSON());

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/store");
        path1.setRecordEvaluateTime(true);
        Value value = path1.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        JPath<?> path2 = jPathParser.parse("/store/book[-2]");
        path2.setRecordEvaluateTime(true);
        value = path2.evaluate(json);
        System.out.println(value.getValueType() + "--> (" + value.nestedSize() + "): " + value.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        JPath<?> path3 = jPathParser.parse("/store/book[2]/title");
        path3.setRecordEvaluateTime(true);
        value = path3.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path3.getLastEvaluateTime() + " ms)");

        JPath<?> path4 = jPathParser.parse("/store/book[$]/title");
        path4.setRecordEvaluateTime(true);
        value = path4.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path4.getLastEvaluateTime() + " ms)");

        JPath<?> path5 = jPathParser.parse("/store/book[last()-3]/title");
        path5.setRecordEvaluateTime(true);
        value = path5.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path5.getLastEvaluateTime() + " ms)");

        JPath<?> path6 = jPathParser.parse("/store/book[last()-1337]/title");
        try {
            value = path6.evaluate(json);
        }
        catch (Exception e) {
            System.out.println(e.toString());
        }

        JPath<?> path7 = JPath.parse("/store/number[$-1337]");
        path7.setRecordEvaluateTime(true);
        value = path7.evaluate(json);
        System.out.println(value.getValueType() + "(" + value.nestedSize() + "): " + value.toJSON() + " (in " + path7.getLastEvaluateTime() + " ms)");

    }
View Full Code Here

        JSON json = JSON.parse(JSONTestExamples.STORE_SAMPLE);

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/store");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        JPath<?> path2 = jPathParser.parse("/store/book[?(@.title=\"Sword of Honour\")]/author");
        path2.setRecordEvaluateTime(true);
        Value value2 = path2.evaluate(json);
        System.out.println(value2.getValueType() + "(" + value2.nestedSize() + "): " + value2.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        JPath<?> path3 = jPathParser.parse("/book[?(@.author=\"J. R. R. Tolkien\")]/title");
        path3.setRecordEvaluateTime(true);
        Value value3 = path3.evaluate(value1);
        System.out.println(value3.getValueType() + "(" + value3.nestedSize() + "): " + value3.toJSON() + " (in " + path3.getLastEvaluateTime() + " ms)");

        JPath<?> path4 = jPathParser.parse("/store/book[?(@.price=8.99)]/title");
        path4.setRecordEvaluateTime(true);
        Value value4 = path4.evaluate(json);
        System.out.println(value4.getValueType() + "(" + value4.nestedSize() + "): " + value4.toJSON() + " (in " + path4.getLastEvaluateTime() + " ms)");
    }
View Full Code Here

        JSON json = JSON.parse(JSONTestExamples.RESUME_SAMPLE);

        JPathParser jPathParser = new JPathParser();
        JPath<?> path1 = jPathParser.parse("/resume/misc\\/other[0]");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        assertEquals("Matrikon Asia-Pacific Heart Award 2005.", value1.getString());

        JPath<?> path2 = jPathParser.parse("/resume/employment[?(@.city=\"Sydney\")]/employer");
        path2.setRecordEvaluateTime(true);
        Value value2 = path2.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value2.nestedSize() + "): " + value2.toJSON() + " (in " + path2.getLastEvaluateTime() + " ms)");

        assertEquals("IBM", value2.getString());
    }
View Full Code Here

        JPathParser jPathParser = new JPathParser();

        JPath<?> path1 = jPathParser.parse("/resume/employment[?(@.city=\"Newcastle\" && @.start date={\"day\":1,\"month\":8,\"year\":2003})]/employer");
        path1.setRecordEvaluateTime(true);
        Value value1 = path1.evaluate(json);
        System.out.println(value1.getValueType() + "(" + value1.nestedSize() + "): " + value1.toJSON() + " (in " + path1.getLastEvaluateTime() + " ms)");

        assertEquals("Matrikon", value1.getString());
    }
View Full Code Here

    @Test
    public void testExpression5() throws IOException, ParserException {
        System.out.println("Test Expression5 - Working Query");
        JSON json = JSON.parse(JSONTestExamples.MC_EXAMPLE);
        Value settingsValue = JPath.parse("/settings").evaluate(json);
        System.out.println("Settings:" + settingsValue);
        assertEquals("java", JPath.parse("/settings/java exe").evaluate(json).getString());
    }
View Full Code Here

    @Test
    public void testExpression11() throws IOException, ParserException {
        System.out.println("Test Expression11 - Array Start Query");
        JSON json = JSON.parse("[{\"blah\":1},{\"blah\":2},{\"blah\":3},{\"blah\":4}]");
        Value value = JPath.parse("/[2]/blah").evaluate(json);
        System.out.println("Value:" + value);
        assertEquals(value.toString(), "3");
    }
View Full Code Here

                + "         \"author\": \"Nigel Rees\",\r\n"
                + "          \"title\": \"Sayings of the Century\",\r\n"
                + "          \"price\": 8.95\r\n"
                + "     }\r\n"
                + "   ]");
        Value value = JPath.parse("/[0]/[?(@.author=\"Nigel Rees\")]/author").evaluate(json);
        System.out.println("Value:" + value);
        assertEquals(value.toString(), "Nigel Rees");
    }
View Full Code Here

        book.setOwner(owner);
        owner.setBook(book);

        System.out.println("0 nested levels");
        JavaMarshaler marshaler = new JavaMarshaler();
        Value output = marshaler.marshalObject(book);
        System.out.println(output.toJSON());

        output = marshaler.marshalObject(owner);
        System.out.println(output.toJSON());

        System.out.println("1 nested level");
        JSONMarshaler.setCycleLevels(1);
        marshaler = new JavaMarshaler();
        output = marshaler.marshalObject(book);
        System.out.println(output.toJSON());

        output = marshaler.marshalObject(owner);
        System.out.println(output.toJSON());

        System.out.println("2 nested levels");
        JSONMarshaler.setCycleLevels(2);
        marshaler = new JavaMarshaler();
        output = marshaler.marshalObject(book);
        System.out.println(output.toJSON());

        output = marshaler.marshalObject(owner);
        System.out.println(output.toJSON());
    }
View Full Code Here

TOP

Related Classes of cc.plural.jsonij.Value

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.