Skip to content

Commit bb55dd0

Browse files
committed
Remove Exclude effect on parent method
1 parent 398807d commit bb55dd0

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

firebase-database/src/main/java/com/google/firebase/database/core/utilities/encoding/CustomClassMapper.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ public BeanMapper(Class<T> clazz) {
497497
// class hierarchy to find the appropriate setter or field.
498498
Class<? super T> currentClass = clazz;
499499
Map<String, Method> bridgeMethods = new HashMap<>();
500-
Set<String> propertyNamesOfExcludedSetters = new HashSet<>();
501500
do {
502501
// Add any setters
503502
for (Method method : currentClass.getDeclaredMethods()) {
@@ -516,12 +515,8 @@ public BeanMapper(Class<T> clazz) {
516515
Method existingSetter = setters.get(propertyName);
517516
Method correspondingBridgeMethod = bridgeMethods.get(propertyName);
518517
if (existingSetter == null) {
518+
method.setAccessible(true);
519519
setters.put(propertyName, method);
520-
if (method.isAnnotationPresent(Exclude.class)) {
521-
propertyNamesOfExcludedSetters.add(propertyName);
522-
} else {
523-
method.setAccessible(true);
524-
}
525520
} else if (!isSetterOverride(method, existingSetter)
526521
&& !(correspondingBridgeMethod != null
527522
&& isSetterOverride(method, correspondingBridgeMethod))) {
@@ -559,14 +554,6 @@ && isSetterOverride(method, correspondingBridgeMethod))) {
559554
currentClass = currentClass.getSuperclass();
560555
} while (currentClass != null && !currentClass.equals(Object.class));
561556

562-
// When subclass setter is annotated with `@Exclude`, the corresponding superclass setter
563-
// also need to be filtered out.
564-
for (String propertyName : propertyNamesOfExcludedSetters) {
565-
Method superclassSetter = setters.get(propertyName);
566-
superclassSetter.setAccessible(false);
567-
setters.remove(propertyName);
568-
}
569-
570557
if (properties.isEmpty()) {
571558
throw new DatabaseException("No properties to serialize found on class " + clazz.getName());
572559
}
@@ -757,7 +744,10 @@ private static boolean shouldIncludeSetter(Method method) {
757744
if (method.getParameterTypes().length != 1) {
758745
return false;
759746
}
760-
747+
// Excluded methods
748+
if (method.isAnnotationPresent(Exclude.class)) {
749+
return false;
750+
}
761751
return true;
762752
}
763753

firebase-firestore/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,4 +890,3 @@ updates.
890890
or
891891
[`FieldValue.serverTimestamp()`](/docs/reference/android/com/google/firebase/firestore/FieldValue.html#serverTimestamp())
892892
values.
893-

firebase-firestore/src/main/java/com/google/firebase/firestore/util/CustomClassMapper.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.util.List;
5151
import java.util.Locale;
5252
import java.util.Map;
53-
import java.util.Set;
5453
import java.util.concurrent.ConcurrentHashMap;
5554
import java.util.concurrent.ConcurrentMap;
5655

@@ -650,7 +649,6 @@ private static class BeanMapper<T> {
650649
// class hierarchy to find the appropriate setter or field.
651650
Class<? super T> currentClass = clazz;
652651
Map<String, Method> bridgeMethods = new HashMap<>();
653-
Set<String> propertyNamesOfExcludedSetters = new HashSet<>();
654652
do {
655653
// Add any setters
656654
for (Method method : currentClass.getDeclaredMethods()) {
@@ -674,9 +672,6 @@ private static class BeanMapper<T> {
674672
if (existingSetter == null) {
675673
setters.put(propertyName, method);
676674
method.setAccessible(true);
677-
if (method.isAnnotationPresent(Exclude.class)) {
678-
propertyNamesOfExcludedSetters.add(propertyName);
679-
}
680675
applySetterAnnotations(method);
681676
} else if (!isSetterOverride(method, existingSetter)
682677
&& !(correspondingBridgeMethod != null
@@ -725,14 +720,6 @@ && isSetterOverride(method, correspondingBridgeMethod))) {
725720
currentClass = currentClass.getSuperclass();
726721
} while (currentClass != null && !currentClass.equals(Object.class));
727722

728-
// When subclass setter is annotated with `@Exclude`, the corresponding superclass setter
729-
// also need to be filtered out.
730-
for (String propertyName : propertyNamesOfExcludedSetters) {
731-
Method superclassSetter = setters.get(propertyName);
732-
superclassSetter.setAccessible(false);
733-
setters.remove(propertyName);
734-
}
735-
736723
if (properties.isEmpty()) {
737724
throw new RuntimeException("No properties to serialize found on class " + clazz.getName());
738725
}
@@ -981,10 +968,6 @@ private void applySetterAnnotations(Method method) {
981968
+ " only be applied to fields and getters, not setters.");
982969
}
983970

984-
if (method.isAnnotationPresent(Exclude.class)) {
985-
method.setAccessible(false);
986-
}
987-
988971
if (method.isAnnotationPresent(DocumentId.class)) {
989972
Class<?> paramType = method.getParameterTypes()[0];
990973
ensureValidDocumentIdType("Method", "accepts", paramType);
@@ -1059,6 +1042,10 @@ private static boolean shouldIncludeSetter(Method method) {
10591042
if (method.getParameterTypes().length != 1) {
10601043
return false;
10611044
}
1045+
// Excluded methods
1046+
if (method.isAnnotationPresent(Exclude.class)) {
1047+
return false;
1048+
}
10621049

10631050
return true;
10641051
}

0 commit comments

Comments
 (0)