Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.OrderedJSONObject


                result = rootObject;
            } else {
                if (!ordered) {
                    result = new JSONObject();
                } else {
                    result = new OrderedJSONObject();
                }
            }

            if (lastToken != Token.TokenBraceL) throw new JSONException("Expecting '{' " + tokenizer.onLineCol() + " instead, obtained token: '" + lastToken + "'");
            lastToken = tokenizer.next();
View Full Code Here


*/
public class OrderedJSONObjectTest extends JSONObjectTest {
    public void test_OrderedJson() {
        String JSON = "{\"attribute\":\"foo\",\"number\":100.959,\"boolean\":true}";
        try {
            OrderedJSONObject obj = new OrderedJSONObject(JSON);
            String jsonStr = obj.write(false);
            assertTrue(jsonStr.equals(JSON));
        } catch (Exception ex) {
            ex.printStackTrace();
            assertTrue(false);
        }
View Full Code Here

     * Rest of removing the first and then adding it back in to see if it shifts to the end.
     */
    public void test_OrderedJsonMove() {
        String JSON = "{\"attribute\":\"foo\", \"number\":100.959, \"boolean\":true}";
        try {
            OrderedJSONObject obj = new OrderedJSONObject(JSON);
            String attribute = (String)obj.remove("attribute");
            obj.put("attribute",attribute);

            String jsonStr = obj.write(false);
            Iterator order = obj.getOrder();

            String[] expectedOrder = new String[] { "number", "boolean", "attribute" };
            int i = 0;
            while (order.hasNext()) {
                assertTrue(expectedOrder[i].equals((String)order.next()));
View Full Code Here

     * Test of removing two entries and ensuring the order is as expected in output
     */
    public void test_OrderedJsonRemove() {
        String JSON = "{\"attribute\":\"foo\", \"number\":100.959, \"boolean\":true, \"banana\":\"sherbert\"}";
        try {
            OrderedJSONObject obj = new OrderedJSONObject(JSON);
            obj.remove("attribute");
            obj.remove("boolean");
            assertTrue(obj.toString().equals("{\"number\":100.959,\"banana\":\"sherbert\"}"));
        } catch (Exception ex) {
            ex.printStackTrace();
            assertTrue(false);
        }
    }
View Full Code Here

     * Test of removing two entries and ensuring the order is as expected in output
     */
    public void test_OrderedJsonRemoveMove() {
        String JSON = "{\"attribute\":\"foo\", \"number\":100.959, \"boolean\":true, \"banana\":\"sherbert\"}";
        try {
            OrderedJSONObject obj = new OrderedJSONObject(JSON);
            obj.remove("attribute");
            Boolean b = (Boolean)obj.remove("boolean");
            obj.put("boolean", b);

            System.out.println("Ordering: " + obj.toString());

            assertTrue(obj.toString().equals("{\"number\":100.959,\"banana\":\"sherbert\",\"boolean\":true}"));
        } catch (Exception ex) {
            ex.printStackTrace();
            assertTrue(false);
        }
    }
View Full Code Here

    /**
     * Test of multiple puts not affecting ordering.
     */
    public void test_OrderedJsonMultiPut() {
        try {
            OrderedJSONObject obj = new OrderedJSONObject();

            obj.put("Entry1", "Value1");
            obj.put("Entry2", "Value2");
            obj.put("Entry3", "Value3");
            obj.put("Entry2", "ReplacedValue2");
            String jsonStr = obj.write(true);
            System.out.println(jsonStr);

            Iterator order = obj.getOrder();
            ArrayList orderList = new ArrayList();
            StringBuffer buf = new StringBuffer("");
            while (order.hasNext()) {
                String next = (String)order.next();
                buf.append(next);
View Full Code Here

    /**
     * Test of clone
     */
    public void test_OrderedClone() {
        try {
            OrderedJSONObject obj = new OrderedJSONObject();

            obj.put("Entry1", "Value1");
            obj.put("Entry2", "Value2");
            obj.put("Entry3", "Value3");
            obj.put("Entry2", "ReplacedValue2");

            OrderedJSONObject clone = (OrderedJSONObject)obj.clone();

            String jsonStr = clone.write(true);
            Iterator order = clone.getOrder();
            ArrayList orderList = new ArrayList();
            StringBuffer buf = new StringBuffer("");
            while (order.hasNext()) {
                String next = (String)order.next();
                buf.append(next);
View Full Code Here

    public void test_OrderedJsonRead() {
        try {
            InputStream is = this.getClass().getClassLoader().getResourceAsStream("utf8_ordered.json");
            ArrayList orderList = new ArrayList();

            OrderedJSONObject obj = new OrderedJSONObject(is);
            is.close();

            String jsonStr = obj.write(true);
            Iterator order = obj.getOrder();
            while (order.hasNext()) {
                String next = (String) order.next();
                orderList.add(next);
            }
            assertTrue(orderList.get(0).equals("First_Entry"));
            assertTrue(orderList.get(1).equals("Second_Entry"));
            assertTrue(orderList.get(2).equals("Third_Entry"));

            //Validate the nested JSONObject was also contructed in an ordered manner.
            OrderedJSONObject jObject = (OrderedJSONObject)obj.get("Second_Entry");
            order = jObject.getOrder();
            orderList.clear();
            StringBuffer buf = new StringBuffer("");
            while (order.hasNext()) {
                String next = (String) order.next();
                orderList.add(next);
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.OrderedJSONObject

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.