Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONObject.optJSONArray()


        Map<String, Object> intArrayProps = new LinkedHashMap<String, Object>();
        intArrayProps.put("numbers", new Integer[]{0, 1, 2});
        Event intArrayEvent = new Event("my/simple/topic", mapToDictionary(intArrayProps));
        JSONObject jIntArray = new JSONObject(JsonEventLogger.constructMessage(intArrayEvent));

        assertNotNull("complex event, int array not null", jIntArray.optJSONArray("numbers"));
        assertEquals("complex event, int array props", 0, jIntArray.getJSONArray("numbers").getInt(0));
        assertEquals("complex event, int array props", 1, jIntArray.getJSONArray("numbers").getInt(1));
        assertEquals("complex event, int array props", 2, jIntArray.getJSONArray("numbers").getInt(2));

        Map<String, Object> mapProps = new LinkedHashMap<String, Object>();
View Full Code Here


        Map<String, Object> stringSetProps = new LinkedHashMap<String, Object>();
        stringSetProps.put("resourceChangedAttributes", new LinkedHashSet<String>(Arrays.asList("first", "second")));
        Event stringSetEvent = new Event("my/simple/topic", mapToDictionary(stringSetProps));
        JSONObject jStringSet = new JSONObject(JsonEventLogger.constructMessage(stringSetEvent));

        assertNotNull("complex event, string set not null", jStringSet.optJSONArray("resourceChangedAttributes"));
        assertEquals("complex event, string set props", "first", jStringSet.getJSONArray("resourceChangedAttributes").getString(0));
        assertEquals("complex event, string set props", "second", jStringSet.getJSONArray("resourceChangedAttributes").getString(1));

    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.