Code example for Stack

Methods: contains, pop, push

0
            this.add("null");
 
            return; 
        } 
 
        if (this.stack.contains(object)) {
            Class clazz = object.getClass();
 
            // cyclic reference 
            if (clazz.isPrimitive() || clazz.equals(String.class)) {
                this.process(object, method);
            } else { 
                if (LOG.isDebugEnabled()) { 
                    LOG.debug("Cyclic reference detected on " + object);
                } 
 
                this.add("null");
            } 
 
            return; 
        } 
 
        this.process(object, method);
    } 
 
    /** 
     * Serialize object into json 
     */ 
    private void process(Object object, Method method) throws JSONException {
        this.stack.push(object);
 
        if (object instanceof Class) {
            this.string(object);
        } else if (object instanceof Boolean) {
            this.bool(((Boolean) object).booleanValue());
        } else if (object instanceof Number) {
            this.add(object);
        } else if (object instanceof String) {
            this.string(object);
        } else if (object instanceof Character) {
            this.string(object);
        } else if (object instanceof Map) {
            this.map((Map) object, method);
        } else if (object.getClass().isArray()) {
            this.array(object, method);
        } else if (object instanceof Iterable) {
            this.array(((Iterable) object).iterator(), method);
        } else if (object instanceof Date) {
            this.date((Date) object, method);
        } else if (object instanceof Calendar) {
            this.date(((Calendar) object).getTime(), method);
        } else if (object instanceof Locale) {
            this.string(object);
        } else if (object instanceof Enum) {
            this.enumeration((Enum) object);
        } else { 
            this.bean(object);
        } 
 
        this.stack.pop();
    } 
 
    /** 
     * Instrospect bean and serialize its properties 
     */