@@ -153,9 +153,14 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
153
153
} else if (value .hasL () && !value .l ().isEmpty () && value .l ().get (0 ).hasM ()) {
154
154
TableSchema <?> elementListSchema = getTableSchemaForListElement (context .tableSchema (), key );
155
155
156
- List <AttributeValue > updatedList = value .l ().stream ()
156
+ List <AttributeValue > updatedList = value .l ()
157
+ .stream ()
157
158
.map (listItem -> listItem .hasM () ?
158
- AttributeValue .builder ().m (processNestedObject (listItem .m (), elementListSchema , currentInstant )).build () : listItem )
159
+ AttributeValue .builder ()
160
+ .m (processNestedObject (listItem .m (),
161
+ elementListSchema ,
162
+ currentInstant ))
163
+ .build () : listItem )
159
164
.collect (Collectors .toList ());
160
165
updatedItems .put (key , AttributeValue .builder ().l (updatedList ).build ());
161
166
}
@@ -165,7 +170,8 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
165
170
166
171
stringTableSchemaMap .forEach ((path , schema ) -> {
167
172
Collection <String > customMetadataObject = schema .tableMetadata ()
168
- .customMetadataObject (CUSTOM_METADATA_KEY , Collection .class ).orElse (null );
173
+ .customMetadataObject (CUSTOM_METADATA_KEY , Collection .class )
174
+ .orElse (null );
169
175
170
176
if (customMetadataObject != null ) {
171
177
customMetadataObject .forEach (
@@ -203,7 +209,8 @@ private TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, S
203
209
}
204
210
String attributeName = parts [parts .length - 1 ];
205
211
listElementSchema = TableSchema .fromClass (
206
- Class .forName (currentSchema .converterForAttribute (attributeName ).type ().rawClassParameters ().get (0 ).rawClass ().getName ()));
212
+ Class .forName (currentSchema .converterForAttribute (attributeName )
213
+ .type ().rawClassParameters ().get (0 ).rawClass ().getName ()));
207
214
}
208
215
} catch (ClassNotFoundException e ) {
209
216
throw new IllegalArgumentException ("Class not found for field name: " + key , e );
@@ -219,11 +226,16 @@ private Map<String, TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeV
219
226
for (String key : attributesToSet .keySet ()) {
220
227
String [] parts = NESTED_OBJECT_PATTERN .split (key );
221
228
222
- String path = "" ;
229
+ StringBuilder pathBuilder = new StringBuilder () ;
223
230
TableSchema <?> currentSchema = rootSchema ;
224
231
225
232
for (int i = 0 ; i < parts .length - 1 ; i ++) {
226
- path = path .isEmpty () ? parts [i ] : path + "." + parts [i ];
233
+ if (pathBuilder .length () > 0 ) {
234
+ pathBuilder .append ("." );
235
+ }
236
+ pathBuilder .append (parts [i ]);
237
+
238
+ String path = pathBuilder .toString ();
227
239
228
240
if (!schemaMap .containsKey (path )) {
229
241
Optional <? extends TableSchema <?>> nestedSchema = getNestedSchema (currentSchema , parts [i ]);
@@ -253,7 +265,7 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
253
265
Collection <String > customMetadataObject = nestedSchema .tableMetadata ()
254
266
.customMetadataObject (CUSTOM_METADATA_KEY , Collection .class ).orElse (null );
255
267
256
- if (customMetadataObject != null ) {
268
+ if (customMetadataObject != null ) {
257
269
customMetadataObject .forEach (
258
270
key -> insertTimestampInItemToTransform (updatedNestedMap , String .valueOf (key ),
259
271
nestedSchema .converterForAttribute (key ), currentInstant ));
@@ -268,11 +280,17 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
268
280
&& nestedValue .l ().get (0 ).hasM ()) {
269
281
try {
270
282
TableSchema <?> listElementSchema = TableSchema .fromClass (
271
- Class .forName (nestedSchema .converterForAttribute (nestedKey ).type ().rawClassParameters ().get (0 ).rawClass ().getName ()));
272
- List <AttributeValue > updatedList = nestedValue .l ().stream ()
273
- .map (listItem -> listItem .hasM () ?
274
- AttributeValue .builder ().m (processNestedObject (listItem .m (), listElementSchema , currentInstant )).build () : listItem )
275
- .collect (Collectors .toList ());
283
+ Class .forName (nestedSchema .converterForAttribute (nestedKey )
284
+ .type ().rawClassParameters ().get (0 ).rawClass ().getName ()));
285
+ List <AttributeValue > updatedList = nestedValue
286
+ .l ()
287
+ .stream ()
288
+ .map (listItem -> listItem .hasM () ?
289
+ AttributeValue .builder ()
290
+ .m (processNestedObject (listItem .m (),
291
+ listElementSchema ,
292
+ currentInstant )).build () : listItem )
293
+ .collect (Collectors .toList ());
276
294
updatedNestedMap .put (nestedKey , AttributeValue .builder ().l (updatedList ).build ());
277
295
} catch (ClassNotFoundException e ) {
278
296
throw new IllegalArgumentException ("Class not found for field name: " + nestedKey , e );
0 commit comments