Skip to content

Commit

Permalink
Remove Exclude effect on parent method
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu committed Feb 16, 2024
1 parent a568bcd commit f027327
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
Expand Up @@ -38,11 +38,9 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -497,7 +495,6 @@ public BeanMapper(Class<T> clazz) {
// class hierarchy to find the appropriate setter or field.
Class<? super T> currentClass = clazz;
Map<String, Method> bridgeMethods = new HashMap<>();
Set<String> propertyNamesOfExcludedSetters = new HashSet<>();
do {
// Add any setters
for (Method method : currentClass.getDeclaredMethods()) {
Expand All @@ -516,12 +513,8 @@ public BeanMapper(Class<T> clazz) {
Method existingSetter = setters.get(propertyName);
Method correspondingBridgeMethod = bridgeMethods.get(propertyName);
if (existingSetter == null) {
method.setAccessible(true);
setters.put(propertyName, method);
if (method.isAnnotationPresent(Exclude.class)) {
propertyNamesOfExcludedSetters.add(propertyName);
} else {
method.setAccessible(true);
}
} else if (!isSetterOverride(method, existingSetter)
&& !(correspondingBridgeMethod != null
&& isSetterOverride(method, correspondingBridgeMethod))) {
Expand Down Expand Up @@ -559,14 +552,6 @@ && isSetterOverride(method, correspondingBridgeMethod))) {
currentClass = currentClass.getSuperclass();
} while (currentClass != null && !currentClass.equals(Object.class));

// When subclass setter is annotated with `@Exclude`, the corresponding superclass setter
// also need to be filtered out.
for (String propertyName : propertyNamesOfExcludedSetters) {
Method superclassSetter = setters.get(propertyName);
superclassSetter.setAccessible(false);
setters.remove(propertyName);
}

if (properties.isEmpty()) {
throw new DatabaseException("No properties to serialize found on class " + clazz.getName());
}
Expand Down Expand Up @@ -757,7 +742,10 @@ private static boolean shouldIncludeSetter(Method method) {
if (method.getParameterTypes().length != 1) {
return false;
}

// Excluded methods
if (method.isAnnotationPresent(Exclude.class)) {
return false;
}
return true;
}

Expand Down
1 change: 0 additions & 1 deletion firebase-firestore/CHANGELOG.md
Expand Up @@ -890,4 +890,3 @@ updates.
or
[`FieldValue.serverTimestamp()`](/docs/reference/android/com/google/firebase/firestore/FieldValue.html#serverTimestamp())
values.

Expand Up @@ -50,7 +50,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -650,7 +649,6 @@ private static class BeanMapper<T> {
// class hierarchy to find the appropriate setter or field.
Class<? super T> currentClass = clazz;
Map<String, Method> bridgeMethods = new HashMap<>();
Set<String> propertyNamesOfExcludedSetters = new HashSet<>();
do {
// Add any setters
for (Method method : currentClass.getDeclaredMethods()) {
Expand All @@ -672,11 +670,8 @@ private static class BeanMapper<T> {
Method existingSetter = setters.get(propertyName);
Method correspondingBridgeMethod = bridgeMethods.get(propertyName);
if (existingSetter == null) {
setters.put(propertyName, method);
method.setAccessible(true);
if (method.isAnnotationPresent(Exclude.class)) {
propertyNamesOfExcludedSetters.add(propertyName);
}
setters.put(propertyName, method);
applySetterAnnotations(method);
} else if (!isSetterOverride(method, existingSetter)
&& !(correspondingBridgeMethod != null
Expand Down Expand Up @@ -725,14 +720,6 @@ && isSetterOverride(method, correspondingBridgeMethod))) {
currentClass = currentClass.getSuperclass();
} while (currentClass != null && !currentClass.equals(Object.class));

// When subclass setter is annotated with `@Exclude`, the corresponding superclass setter
// also need to be filtered out.
for (String propertyName : propertyNamesOfExcludedSetters) {
Method superclassSetter = setters.get(propertyName);
superclassSetter.setAccessible(false);
setters.remove(propertyName);
}

if (properties.isEmpty()) {
throw new RuntimeException("No properties to serialize found on class " + clazz.getName());
}
Expand Down Expand Up @@ -981,10 +968,6 @@ private void applySetterAnnotations(Method method) {
+ " only be applied to fields and getters, not setters.");
}

if (method.isAnnotationPresent(Exclude.class)) {
method.setAccessible(false);
}

if (method.isAnnotationPresent(DocumentId.class)) {
Class<?> paramType = method.getParameterTypes()[0];
ensureValidDocumentIdType("Method", "accepts", paramType);
Expand Down Expand Up @@ -1059,7 +1042,10 @@ private static boolean shouldIncludeSetter(Method method) {
if (method.getParameterTypes().length != 1) {
return false;
}

// Excluded methods
if (method.isAnnotationPresent(Exclude.class)) {
return false;
}
return true;
}

Expand Down

0 comments on commit f027327

Please sign in to comment.