@@ -153,9 +153,14 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
153153 } else if (value .hasL () && !value .l ().isEmpty () && value .l ().get (0 ).hasM ()) {
154154 TableSchema <?> elementListSchema = getTableSchemaForListElement (context .tableSchema (), key );
155155
156- List <AttributeValue > updatedList = value .l ().stream ()
156+ List <AttributeValue > updatedList = value .l ()
157+ .stream ()
157158 .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 )
159164 .collect (Collectors .toList ());
160165 updatedItems .put (key , AttributeValue .builder ().l (updatedList ).build ());
161166 }
@@ -165,7 +170,8 @@ public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite contex
165170
166171 stringTableSchemaMap .forEach ((path , schema ) -> {
167172 Collection <String > customMetadataObject = schema .tableMetadata ()
168- .customMetadataObject (CUSTOM_METADATA_KEY , Collection .class ).orElse (null );
173+ .customMetadataObject (CUSTOM_METADATA_KEY , Collection .class )
174+ .orElse (null );
169175
170176 if (customMetadataObject != null ) {
171177 customMetadataObject .forEach (
@@ -203,7 +209,8 @@ private TableSchema<?> getTableSchemaForListElement(TableSchema<?> rootSchema, S
203209 }
204210 String attributeName = parts [parts .length - 1 ];
205211 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 ()));
207214 }
208215 } catch (ClassNotFoundException e ) {
209216 throw new IllegalArgumentException ("Class not found for field name: " + key , e );
@@ -219,11 +226,16 @@ private Map<String, TableSchema<?>> resolveSchemasPerPath(Map<String, AttributeV
219226 for (String key : attributesToSet .keySet ()) {
220227 String [] parts = NESTED_OBJECT_PATTERN .split (key );
221228
222- String path = "" ;
229+ StringBuilder pathBuilder = new StringBuilder () ;
223230 TableSchema <?> currentSchema = rootSchema ;
224231
225232 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 ();
227239
228240 if (!schemaMap .containsKey (path )) {
229241 Optional <? extends TableSchema <?>> nestedSchema = getNestedSchema (currentSchema , parts [i ]);
@@ -253,7 +265,7 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
253265 Collection <String > customMetadataObject = nestedSchema .tableMetadata ()
254266 .customMetadataObject (CUSTOM_METADATA_KEY , Collection .class ).orElse (null );
255267
256- if (customMetadataObject != null ) {
268+ if (customMetadataObject != null ) {
257269 customMetadataObject .forEach (
258270 key -> insertTimestampInItemToTransform (updatedNestedMap , String .valueOf (key ),
259271 nestedSchema .converterForAttribute (key ), currentInstant ));
@@ -268,11 +280,17 @@ private Map<String, AttributeValue> processNestedObject(Map<String, AttributeVal
268280 && nestedValue .l ().get (0 ).hasM ()) {
269281 try {
270282 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 ());
276294 updatedNestedMap .put (nestedKey , AttributeValue .builder ().l (updatedList ).build ());
277295 } catch (ClassNotFoundException e ) {
278296 throw new IllegalArgumentException ("Class not found for field name: " + nestedKey , e );
0 commit comments