@@ -193,49 +193,49 @@ private void extractPropertiesFromServices(Properties properties,
193
193
}
194
194
}
195
195
196
+ @ SuppressWarnings ("unchecked" )
196
197
private void flatten (Properties properties , Map <String , Object > input , String path ) {
197
198
for (Entry <String , Object > entry : input .entrySet ()) {
198
- String key = entry .getKey ();
199
- if (StringUtils .hasText (path )) {
200
- if (key .startsWith ("[" )) {
201
- key = path + key ;
202
- }
203
- else {
204
- key = path + "." + key ;
205
- }
206
- }
199
+ String key = getFullKey (path , entry .getKey ());
207
200
Object value = entry .getValue ();
208
- if (value instanceof String ) {
209
- properties .put (key , value );
210
- }
211
- else if (value instanceof Number ) {
212
- properties .put (key , value .toString ());
213
- }
214
- else if (value instanceof Boolean ) {
215
- properties .put (key , value .toString ());
216
- }
217
- else if (value instanceof Map ) {
201
+ if (value instanceof Map ) {
218
202
// Need a compound key
219
- @ SuppressWarnings ("unchecked" )
220
- Map <String , Object > map = (Map <String , Object >) value ;
221
- flatten (properties , map , key );
203
+ flatten (properties , (Map <String , Object >) value , key );
222
204
}
223
205
else if (value instanceof Collection ) {
224
206
// Need a compound key
225
- @ SuppressWarnings ("unchecked" )
226
207
Collection <Object > collection = (Collection <Object >) value ;
227
208
properties .put (key ,
228
209
StringUtils .collectionToCommaDelimitedString (collection ));
229
210
int count = 0 ;
230
- for (Object object : collection ) {
231
- flatten ( properties ,
232
- Collections .singletonMap ("[" + ( count ++) + "]" , object ), key );
211
+ for (Object item : collection ) {
212
+ String itemKey = "[" + ( count ++) + "]" ;
213
+ flatten ( properties , Collections .singletonMap (itemKey , item ), key );
233
214
}
234
215
}
216
+ else if (value instanceof String ) {
217
+ properties .put (key , value );
218
+ }
219
+ else if (value instanceof Number ) {
220
+ properties .put (key , value .toString ());
221
+ }
222
+ else if (value instanceof Boolean ) {
223
+ properties .put (key , value .toString ());
224
+ }
235
225
else {
236
226
properties .put (key , value == null ? "" : value );
237
227
}
238
228
}
239
229
}
240
230
231
+ private String getFullKey (String path , String key ) {
232
+ if (!StringUtils .hasText (path )) {
233
+ return key ;
234
+ }
235
+ if (key .startsWith ("[" )) {
236
+ return path + key ;
237
+ }
238
+ return path + "." + key ;
239
+ }
240
+
241
241
}
0 commit comments