com.aeontronix.enhancedmule.tools.util.JacksonFlattener Maven / Gradle / Ivy
/*
* Copyright (c) Aeontronix 2023
*/
package com.aeontronix.enhancedmule.propertiesprovider.utils;
import com.aeontronix.commons.StringUtils;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
@SuppressWarnings("unchecked")
public class JacksonFlattener {
/**
* Flatten a hierarchical {@link Map} into a flat {@link Map} with key names using
* property dot notation.
*
* @param inputMap must not be {@literal null}.
* @return the resulting {@link Map}.
* @since 2.0
*/
public static Map flattenToStringMap(Map inputMap) {
Map resultMap = new LinkedHashMap<>();
doFlatten("", inputMap.entrySet().iterator(), resultMap, it -> it == null ? null : it.toString());
return resultMap;
}
private static void doFlatten(String propertyPrefix, Iterator extends Map.Entry> inputMap,
Map resultMap, Function