Package com.google.gson

Examples of com.google.gson.JsonObject


     * @throws Exception if failed
     */
    @Test
    public void simple() throws Exception {
        DataModelDefinition<Simple> def = new SimpleDataModelDefinition<Simple>(Simple.class);
        JsonObject json = new JsonObject();
        json.addProperty("number", 100);
        json.addProperty("text", "Hello, world!");

        DataModelReflection ref = JsonObjectDriver.convert(def, json);
        Simple object = def.toObject(ref);

        assertThat(object.number, is(100));
View Full Code Here


     * @throws Exception if failed
     */
    @Test
    public void invalid_property() throws Exception {
        DataModelDefinition<Simple> def = new SimpleDataModelDefinition<Simple>(Simple.class);
        JsonObject json = new JsonObject();
        json.addProperty("invalid", 100);
        json.addProperty("text", "Hello, world!");

        DataModelReflection ref = JsonObjectDriver.convert(def, json);
        Simple object = def.toObject(ref);

        assertThat(object.number, is(nullValue()));
View Full Code Here

     * @throws Exception if failed
     */
    @Test(expected = IOException.class)
    public void inconsistent_type() throws Exception {
        DataModelDefinition<Simple> def = new SimpleDataModelDefinition<Simple>(Simple.class);
        JsonObject json = new JsonObject();
        json.addProperty("number", "QQQ");
        json.addProperty("text", "Hello, world!");

        JsonObjectDriver.convert(def, json);
    }
View Full Code Here

     * @throws Exception if failed
     */
    @Test
    public void types() throws Exception {
        DataModelDefinition<Simple> def = new SimpleDataModelDefinition<Simple>(Simple.class);
        JsonObject json = new JsonObject();
        json.addProperty("boolean_value", true);
        json.addProperty("byte_value", (byte) 100);
        json.addProperty("short_value", (short) 200);
        json.addProperty("long_value", 300L);
        json.addProperty("big_integer_value", new BigInteger("123456"));
        json.addProperty("float_value", 1.0f);
        json.addProperty("double_value", 1.5d);
        json.addProperty("big_decimal_value", new BigDecimal("12.3456"));
        json.addProperty("date_value", "2012-01-02");
        json.addProperty("datetime_value", "2011-12-31 10:20:30");

        DataModelReflection ref = JsonObjectDriver.convert(def, json);
        Simple object = def.toObject(ref);

        assertThat(object.booleanValue, is(true));
View Full Code Here

        return 0;
    }

    private static void explainBatch(BatchScript script) throws IOException {
        assert script != null;
        JsonObject batch = analyzeBatch(script);
        Gson gson = new GsonBuilder()
            .disableHtmlEscaping()
            .setPrettyPrinting()
            .create();
        Writer writer = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
View Full Code Here

    private static JsonObject analyzeBatch(BatchScript script) {
        assert script != null;
        JsonArray jobflows = new JsonArray();
        for (FlowScript flowScript : script.getAllFlows()) {
            JsonObject jobflow = analyzeJobflow(flowScript);
            jobflows.add(jobflow);
        }
        JsonObject batch = new JsonObject();
        batch.addProperty("id", script.getId());
        batch.add("jobflows", jobflows);
        return batch;
    }
View Full Code Here

                    || phase == ExecutionPhase.SETUP
                    || phase == ExecutionPhase.CLEANUP) {
                phases.add(new JsonPrimitive(phase.getSymbol()));
            }
        }
        JsonObject jobflow = new JsonObject();
        jobflow.addProperty("id", flowScript.getId());
        jobflow.add("blockers", toJsonArray(flowScript.getBlockerIds()));
        jobflow.add("phases", phases);
        return jobflow;
    }
View Full Code Here

     * status (waiting).
     * @throws Exception if failed
     */
    @Test
    public void status_waiting() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "waiting");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);

View Full Code Here

     * status (running).
     * @throws Exception if failed
     */
    @Test
    public void status_running() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "running");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);

View Full Code Here

     * status (completed).
     * @throws Exception if failed
     */
    @Test
    public void status_completed() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "completed");
        result.addProperty("jrid", "testing");
        result.addProperty("exitCode", "1");

        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
View Full Code Here

TOP

Related Classes of com.google.gson.JsonObject

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.