modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JavaBean2JSONObject.java [90:129]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public Object toJSON(Object source) throws Exception {
        if (source == null) {
            return JSONObject.NULL;
        }
        Class<?> type = source.getClass();
        if (isSimpleType(type)) {
            return source;
        } else if (type.isArray()) {
            JSONArray array = new JSONArray();
            int i1 = Array.getLength(source);
            for (int j = 0; j < i1; j++) {
                Object o = Array.get(source, j);
                array.put(toJSON(o));
            }
            return array;
        } else if (Collection.class.isAssignableFrom(type)) {
            Collection c = (Collection)source;
            JSONArray array = new JSONArray();
            for (Object element : c) {
                array.put(toJSON(element));
            }
            return array;
        }
        JSONObject json = new JSONObject();
        BeanInfo beanInfo = Introspector.getBeanInfo(type);
        PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors();
        Collections.sort(Arrays.asList(propDescs), COMPARATOR);

        for (int i = 0; i < propDescs.length; i++) {
            PropertyDescriptor propDesc = propDescs[i];
            Class<?> pType = propDesc.getPropertyType();
            if ("class".equals(propDesc.getName())) {
                continue;
            }
            Object pValue = propDesc.getReadMethod().invoke(source, NULL);
            json.put(propDesc.getName(), toJSON(pValue));
        }
        return json;

    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/databinding-json-2-x/src/main/java/org/apache/tuscany/sca/databinding/json2x/JavaBean2JSONObject.java [93:132]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public Object toJSON(Object source) throws Exception {
        if (source == null) {
            return JSONObject.NULL;
        }
        Class<?> type = source.getClass();
        if (isSimpleType(type)) {
            return source;
        } else if (type.isArray()) {
            JSONArray array = new JSONArray();
            int i1 = Array.getLength(source);
            for (int j = 0; j < i1; j++) {
                Object o = Array.get(source, j);
                array.put(toJSON(o));
            }
            return array;
        } else if (Collection.class.isAssignableFrom(type)) {
            Collection c = (Collection)source;
            JSONArray array = new JSONArray();
            for (Object element : c) {
                array.put(toJSON(element));
            }
            return array;
        }
        JSONObject json = new JSONObject();
        BeanInfo beanInfo = Introspector.getBeanInfo(type);
        PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors();
        Collections.sort(Arrays.asList(propDescs), COMPARATOR);

        for (int i = 0; i < propDescs.length; i++) {
            PropertyDescriptor propDesc = propDescs[i];
            Class<?> pType = propDesc.getPropertyType();
            if ("class".equals(propDesc.getName())) {
                continue;
            }
            Object pValue = propDesc.getReadMethod().invoke(source, NULL);
            json.put(propDesc.getName(), toJSON(pValue));
        }
        return json;

    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



