Skip to content

Commit bef87cc

Browse files
committed
add @transient to not store fields.
1 parent 48abf07 commit bef87cc

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>in.kuros</groupId>
1414
<artifactId>jFirebase</artifactId>
15-
<version>1.0.0</version>
15+
<version>1.0.1</version>
1616

1717

1818
<description>This project aims at building a wrapper over nosql technologies - Firebase</description>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package in.kuros.jfirebase.entity;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.FIELD)
10+
public @interface Transient {
11+
}

src/main/java/in/kuros/jfirebase/util/BeanMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import in.kuros.jfirebase.entity.Parent;
1212
import in.kuros.jfirebase.entity.Temporal;
1313
import in.kuros.jfirebase.entity.TemporalType;
14+
import in.kuros.jfirebase.entity.Transient;
1415
import in.kuros.jfirebase.entity.UpdateTime;
1516
import lombok.Getter;
1617
import lombok.SneakyThrows;
@@ -23,9 +24,11 @@
2324
import java.lang.reflect.Type;
2425
import java.util.Date;
2526
import java.util.HashMap;
27+
import java.util.HashSet;
2628
import java.util.Locale;
2729
import java.util.Map;
2830
import java.util.Optional;
31+
import java.util.Set;
2932

3033
@Getter
3134
public class BeanMapper<T> {
@@ -40,6 +43,7 @@ public class BeanMapper<T> {
4043
private final Map<String, Method> getters;
4144
private final Map<String, Method> setters;
4245
private final Map<String, Field> fields;
46+
private final Set<String> transients;
4347
private final Map<String, Temporal> temporals;
4448
private final String createTime;
4549
private final String updateTime;
@@ -56,6 +60,7 @@ public BeanMapper(final Class<T> clazz) {
5660
this.idReferences = new HashMap<>();
5761
this.parent = new HashMap<>();
5862
this.temporals = new HashMap<>();
63+
this.transients = new HashSet<>();
5964

6065
Constructor<T> constructor;
6166
try {
@@ -86,6 +91,9 @@ public BeanMapper(final Class<T> clazz) {
8691

8792
final Field declaredField = clazz.getDeclaredField(propertyName);
8893
declaredField.setAccessible(true);
94+
if (declaredField.isAnnotationPresent(Transient.class)) {
95+
transients.add(propertyName);
96+
}
8997
if (idProperty != null && declaredField.isAnnotationPresent(Id.class)) {
9098
throw new EntityDeclarationException("Multiple @Id mapping found or class: " + clazz.getName());
9199
} else if (declaredField.isAnnotationPresent(Id.class)) {
@@ -211,6 +219,10 @@ public Map<String, Object> serialize(T object) {
211219
Map<String, Object> result = new HashMap<>();
212220
for (String property : properties.values()) {
213221

222+
if (transients.contains(property)) {
223+
continue;
224+
}
225+
214226
Object propertyValue;
215227
if (getters.containsKey(property)) {
216228
Method getter = getters.get(property);

0 commit comments

Comments
 (0)