|
5 | 5 | import in.kuros.jfirebase.metadata.AttributeValue; |
6 | 6 | import in.kuros.jfirebase.metadata.MapAttributeValue; |
7 | 7 | import in.kuros.jfirebase.metadata.ValuePath; |
| 8 | +import in.kuros.jfirebase.util.BeanMapper; |
8 | 9 | import in.kuros.jfirebase.util.ClassMapper; |
9 | 10 |
|
10 | 11 | import java.lang.reflect.Constructor; |
@@ -96,20 +97,33 @@ private <T> Class<T> getDeclaringClass(final List<AttributeValue<T, ?>> attribut |
96 | 97 | public <T> Map<String, Object> convertToObjectMap(final List<AttributeValue<T, ?>> attributeValues) { |
97 | 98 | final Map<String, Object> result = new HashMap<>(); |
98 | 99 |
|
| 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 | + |
99 | 107 | for (AttributeValue<T, ?> attributeValue : attributeValues) { |
| 108 | + final String propertyName = attributeValue.getAttribute().getName(); |
100 | 109 | if (MapAttributeValue.class.isAssignableFrom(attributeValue.getClass()) |
101 | 110 | && ((MapAttributeValue) attributeValue).isKeyUpdate()) { |
102 | 111 | final MapAttributeValue mapAttributeValue = (MapAttributeValue) attributeValue; |
103 | 112 | if (!(mapAttributeValue.getKey() instanceof String)) { |
104 | 113 | throw new IllegalArgumentException("Object keys are not supported in firebase/firestore"); |
105 | 114 | } |
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<>()); |
108 | 116 | mapField.put((String) mapAttributeValue.getKey(), ClassMapper.serialize(mapAttributeValue.getMapValue().getValue())); |
109 | | - result.put(attributeName, mapField); |
| 117 | + result.put(propertyName, mapField); |
110 | 118 | } else { |
111 | | - result.put(attributeValue.getAttribute().getName(), ClassMapper.serialize(attributeValue.getAttributeValue().getValue())); |
| 119 | + result.put(propertyName, ClassMapper.serialize(attributeValue.getAttributeValue().getValue())); |
112 | 120 | } |
| 121 | + |
| 122 | + if (beanMapper.getTemporals().containsKey(propertyName)) { |
| 123 | + final Object parsedValue = beanMapper.parseTemporalValues(propertyName, result.get(propertyName)); |
| 124 | + result.put(propertyName, parsedValue); |
| 125 | + } |
| 126 | + |
113 | 127 | } |
114 | 128 |
|
115 | 129 | return result; |
|
0 commit comments