下面列出了怎么用com.alibaba.fastjson.serializer.JavaBeanSerializer的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Collection<Object> getPropertyValues(final Object currentObject) {
final Class<?> currentClass = currentObject.getClass();
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);
if (beanSerializer != null) {
try {
return beanSerializer.getFieldValues(currentObject);
} catch (Exception e) {
throw new JSONPathException("jsonpath error, path " + path, e);
}
}
if (currentObject instanceof Map) {
Map map = (Map) currentObject;
return map.values();
}
throw new UnsupportedOperationException();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Collection<Object> getPropertyValues(final Object currentObject) {
final Class<?> currentClass = currentObject.getClass();
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);
if (beanSerializer != null) {
try {
return beanSerializer.getFieldValues(currentObject);
} catch (Exception e) {
throw new JSONPathException("jsonpath error, path " + path, e);
}
}
if (currentObject instanceof Map) {
Map map = (Map) currentObject;
return map.values();
}
if (currentObject instanceof Collection) {
return (Collection) currentObject;
}
throw new UnsupportedOperationException();
}
@SuppressWarnings({"rawtypes", "unchecked"})
Set<?> evalKeySet(Object currentObject) {
if (currentObject == null) {
return null;
}
if (currentObject instanceof Map) {
// For performance reasons return keySet directly, without filtering null-value key.
return ((Map)currentObject).keySet();
}
if (currentObject instanceof Collection || currentObject instanceof Object[]
|| currentObject.getClass().isArray()) {
return null;
}
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());
if (beanSerializer == null) {
return null;
}
try {
return beanSerializer.getFieldNames(currentObject);
} catch (Exception e) {
throw new JSONPathException("evalKeySet error : " + path, e);
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
Set<?> evalKeySet(Object currentObject) {
if (currentObject == null) {
return null;
}
if (currentObject instanceof Map) {
// For performance reasons return keySet directly, without filtering null-value key.
return ((Map)currentObject).keySet();
}
if (currentObject instanceof Collection || currentObject instanceof Object[]
|| currentObject.getClass().isArray()) {
return null;
}
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());
if (beanSerializer == null) {
return null;
}
try {
return beanSerializer.getFieldNames(currentObject);
} catch (Exception e) {
throw new JSONPathException("evalKeySet error : " + path, e);
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Collection<Object> getPropertyValues(final Object currentObject) {
if (currentObject == null) {
return null;
}
final Class<?> currentClass = currentObject.getClass();
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);
if (beanSerializer != null) {
try {
return beanSerializer.getFieldValues(currentObject);
} catch (Exception e) {
throw new JSONPathException("jsonpath error, path " + path, e);
}
}
if (currentObject instanceof Map) {
Map map = (Map) currentObject;
return map.values();
}
if (currentObject instanceof Collection) {
return (Collection) currentObject;
}
throw new UnsupportedOperationException();
}
@SuppressWarnings({"rawtypes", "unchecked"})
Set<?> evalKeySet(Object currentObject) {
if (currentObject == null) {
return null;
}
if (currentObject instanceof Map) {
// For performance reasons return keySet directly, without filtering null-value key.
return ((Map)currentObject).keySet();
}
if (currentObject instanceof Collection || currentObject instanceof Object[]
|| currentObject.getClass().isArray()) {
return null;
}
JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentObject.getClass());
if (beanSerializer == null) {
return null;
}
try {
return beanSerializer.getFieldNames(currentObject);
} catch (Exception e) {
throw new JSONPathException("evalKeySet error : " + path, e);
}
}
@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);
}
}
@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);
}
}
@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);
}
}