Java Code Examples for com.alibaba.fastjson.serializer.JavaBeanSerializer#getSize()

The following examples show how to use com.alibaba.fastjson.serializer.JavaBeanSerializer#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONPath.java    From uavstack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
int evalSize(Object currentObject) {
    if (currentObject == null) {
        return -1;
    }

    if (currentObject instanceof Collection) {
        return ((Collection) currentObject).size();
    }

    if (currentObject instanceof Object[]) {
        return ((Object[]) currentObject).length;
    }

    if (currentObject.getClass().isArray()) {
        return Array.getLength(currentObject);
    }

    if (currentObject instanceof Map) {
        int count = 0;

        for (Object value : ((Map) currentObject).values()) {
            if (value != null) {
                count++;
            }
        }
        return count;
    }

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());

    if (beanSerializer == null) {
        return -1;
    }

    try {
        return beanSerializer.getSize(currentObject);
    } catch (Exception e) {
        throw new JSONPathException("evalSize error : " + path, e);
    }
}
 
Example 2
Source File: JSONPath_s.java    From coming with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
int evalSize(Object currentObject) {
    if (currentObject == null) {
        return -1;
    }

    if (currentObject instanceof Collection) {
        return ((Collection) currentObject).size();
    }

    if (currentObject instanceof Object[]) {
        return ((Object[]) currentObject).length;
    }

    if (currentObject.getClass().isArray()) {
        return Array.getLength(currentObject);
    }

    if (currentObject instanceof Map) {
        int count = 0;

        for (Object value : ((Map) currentObject).values()) {
            if (value != null) {
                count++;
            }
        }
        return count;
    }

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());

    if (beanSerializer == null) {
        return -1;
    }

    try {
        return beanSerializer.getSize(currentObject);
    } catch (Exception e) {
        throw new JSONPathException("evalSize error : " + path, e);
    }
}
 
Example 3
Source File: JSONPath_t.java    From coming with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
int evalSize(Object currentObject) {
    if (currentObject == null) {
        return -1;
    }

    if (currentObject instanceof Collection) {
        return ((Collection) currentObject).size();
    }

    if (currentObject instanceof Object[]) {
        return ((Object[]) currentObject).length;
    }

    if (currentObject.getClass().isArray()) {
        return Array.getLength(currentObject);
    }

    if (currentObject instanceof Map) {
        int count = 0;

        for (Object value : ((Map) currentObject).values()) {
            if (value != null) {
                count++;
            }
        }
        return count;
    }

    JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());

    if (beanSerializer == null) {
        return -1;
    }

    try {
        return beanSerializer.getSize(currentObject);
    } catch (Exception e) {
        throw new JSONPathException("evalSize error : " + path, e);
    }
}