/** * Format the string with this format. * * @param str The string * @return The formatted string */ public String format(String str) { return StringConvention.format(this, str); }
private void processSubmapKey(Map<String, Object> map, String key, Object value, StringConvention keyConvention) { int index = key.indexOf('.'); if (index == -1) { key = keyConvention.format(key); map.put(key, value); } else { String mapKey = key.substring(0, index); mapKey = keyConvention.format(mapKey); if (!map.containsKey(mapKey)) { map.put(mapKey, new LinkedHashMap<>()); } final Object v = map.get(mapKey); if (v instanceof Map) { Map<String, Object> nestedMap = (Map<String, Object>) v; String nestedKey = key.substring(index + 1); processSubmapKey(nestedMap, nestedKey, value, keyConvention); } else { map.put(mapKey, v); } } }
/** * @param name The property name * @param entries The entries * @param conversionContext The conversion context * @return The subproperties */ protected Properties resolveSubProperties(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) { // special handling for maps for resolving sub keys Properties properties = new Properties(); AnnotationMetadata annotationMetadata = conversionContext.getAnnotationMetadata(); StringConvention keyConvention = annotationMetadata.getValue(MapFormat.class, "keyFormat", StringConvention.class) .orElse(StringConvention.RAW); String prefix = name + '.'; entries.entrySet().stream() .filter(map -> map.getKey().startsWith(prefix)) .forEach(entry -> { Object value = entry.getValue(); if (value != null) { String key = entry.getKey().substring(prefix.length()); key = keyConvention.format(key); properties.put(key, resolvePlaceHoldersIfNecessary(value.toString())); } }); return properties; }
/** * @param name The property name * @param entries The entries * @param conversionContext The conversion context * @return The subproperties */ protected Properties resolveSubProperties(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) { // special handling for maps for resolving sub keys Properties properties = new Properties(); AnnotationMetadata annotationMetadata = conversionContext.getAnnotationMetadata(); StringConvention keyConvention = annotationMetadata.getValue(MapFormat.class, "keyFormat", StringConvention.class) .orElse(StringConvention.RAW); String prefix = name + '.'; entries.entrySet().stream() .filter(map -> map.getKey().startsWith(prefix)) .forEach(entry -> { Object value = entry.getValue(); if (value != null) { String key = entry.getKey().substring(prefix.length()); key = keyConvention.format(key); properties.put(key, resolvePlaceHoldersIfNecessary(value.toString())); } }); return properties; }
subMapKey = keyConvention.format(subMapKey); subMap.put(subMapKey, value); } else { int index = subMapKey.indexOf('.'); if (index == -1) { subMapKey = keyConvention.format(subMapKey); subMap.put(subMapKey, value); } else { mapKey = keyConvention.format(mapKey); if (!subMap.containsKey(mapKey)) { subMap.put(mapKey, new LinkedHashMap<>()); keyConvention.format(nestedKey); nestedMap.put(nestedKey, value); } else {
subMapKey = keyConvention.format(subMapKey); value = conversionService.convert(value, valueType).orElse(null); subMap.put(subMapKey, value);