From 8f57c3ca99765dda30741983a572ecbce4558f4e Mon Sep 17 00:00:00 2001 From: Victor Verbitsky Date: Thu, 10 Jul 2014 20:10:06 +0400 Subject: [PATCH] Skip serialization of transient members. Performing serialization of inherited fields. --- .../serial/graph/node/AccessNode.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/serial/base/src/main/java/org/switchyard/serial/graph/node/AccessNode.java b/serial/base/src/main/java/org/switchyard/serial/graph/node/AccessNode.java index fe53e11cd..0f2f872a3 100644 --- a/serial/base/src/main/java/org/switchyard/serial/graph/node/AccessNode.java +++ b/serial/base/src/main/java/org/switchyard/serial/graph/node/AccessNode.java @@ -17,6 +17,7 @@ import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; +import java.beans.Transient; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -182,6 +183,9 @@ private List getAccessList(Class clazz) { } for (PropertyDescriptor desc : info.getPropertyDescriptors()) { Method readMethod = desc.getReadMethod(); + if (readMethod.isAnnotationPresent(Transient.class)) { + continue; + } if (((CoverageType.INCLUSIVE.equals(coverageType) && readMethod.getAnnotation(Exclude.class) == null) || (CoverageType.EXCLUSIVE.equals(coverageType) @@ -221,22 +225,35 @@ private List getAccessList(Class clazz) { } break; case FIELD: - for (Field field : clazz.getDeclaredFields()) { - if (((CoverageType.INCLUSIVE.equals(coverageType) - && field.getAnnotation(Exclude.class) == null) - || (CoverageType.EXCLUSIVE.equals(coverageType) - && field.getAnnotation(Include.class) != null)) - && field.getAnnotation(Deprecated.class) == null - && !Modifier.isTransient(field.getModifiers())) { - Access access = new FieldAccess(field); - if (access.isReadable()) { - accessList.add(access); + Class cl = clazz; + while (cl != null && cl != Object.class) { + for (Field field : cl.getDeclaredFields()) { + if (Modifier.isTransient(field.getModifiers())) { + continue; + } + if (((CoverageType.INCLUSIVE.equals(coverageType) + && field.getAnnotation(Exclude.class) == null) + || (CoverageType.EXCLUSIVE.equals(coverageType) + && field.getAnnotation(Include.class) != null)) + && field.getAnnotation(Deprecated.class) == null) { + Access access = new FieldAccess(field); + if (access.isReadable()) { + accessList.add(access); + } } } + cl = cl.getSuperclass(); } break; } return accessList; } + private AccessType getDefaultAccessType(Class clazz) { + if (clazz.getPackage().getName().startsWith("org.switchyard")) { + return AccessType.BEAN; + } + return AccessType.FIELD; + } + }