Skip to content

Commit 91572e4

Browse files
committed
fix @TeMPOraL for set/update attribute
1 parent a156ad6 commit 91572e4

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/main/java/in/kuros/jfirebase/provider/firebase/AttributeValueHelper.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import in.kuros.jfirebase.metadata.AttributeValue;
66
import in.kuros.jfirebase.metadata.MapAttributeValue;
77
import in.kuros.jfirebase.metadata.ValuePath;
8+
import in.kuros.jfirebase.util.BeanMapper;
89
import in.kuros.jfirebase.util.ClassMapper;
910

1011
import java.lang.reflect.Constructor;
@@ -96,20 +97,33 @@ private <T> Class<T> getDeclaringClass(final List<AttributeValue<T, ?>> attribut
9697
public <T> Map<String, Object> convertToObjectMap(final List<AttributeValue<T, ?>> attributeValues) {
9798
final Map<String, Object> result = new HashMap<>();
9899

100+
if (attributeValues.isEmpty()) {
101+
return result;
102+
}
103+
104+
final Class<T> declaringType = attributeValues.get(0).getAttribute().getDeclaringType();
105+
final BeanMapper<T> beanMapper = ClassMapper.getBeanMapper(declaringType);
106+
99107
for (AttributeValue<T, ?> attributeValue : attributeValues) {
108+
final String propertyName = attributeValue.getAttribute().getName();
100109
if (MapAttributeValue.class.isAssignableFrom(attributeValue.getClass())
101110
&& ((MapAttributeValue) attributeValue).isKeyUpdate()) {
102111
final MapAttributeValue mapAttributeValue = (MapAttributeValue) attributeValue;
103112
if (!(mapAttributeValue.getKey() instanceof String)) {
104113
throw new IllegalArgumentException("Object keys are not supported in firebase/firestore");
105114
}
106-
final String attributeName = attributeValue.getAttribute().getName();
107-
final Map<String, Object> mapField = (Map<String, Object>) result.getOrDefault(attributeName, new HashMap<>());
115+
final Map<String, Object> mapField = (Map<String, Object>) result.getOrDefault(propertyName, new HashMap<>());
108116
mapField.put((String) mapAttributeValue.getKey(), ClassMapper.serialize(mapAttributeValue.getMapValue().getValue()));
109-
result.put(attributeName, mapField);
117+
result.put(propertyName, mapField);
110118
} else {
111-
result.put(attributeValue.getAttribute().getName(), ClassMapper.serialize(attributeValue.getAttributeValue().getValue()));
119+
result.put(propertyName, ClassMapper.serialize(attributeValue.getAttributeValue().getValue()));
112120
}
121+
122+
if (beanMapper.getTemporals().containsKey(propertyName)) {
123+
final Object parsedValue = beanMapper.parseTemporalValues(propertyName, result.get(propertyName));
124+
result.put(propertyName, parsedValue);
125+
}
126+
113127
}
114128

115129
return result;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public Map<String, Object> serialize(T object) {
246246
return result;
247247
}
248248

249-
private Object parseTemporalValues(final String property, Object propertyValue) {
249+
public Object parseTemporalValues(final String property, Object propertyValue) {
250250
if (temporals.containsKey(property)) {
251251
final Temporal temporal = temporals.get(property);
252252
if (temporal.value() == TemporalType.DATE) {

0 commit comments

Comments
 (0)