package com.boman.domain.utils;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.CaseFormat;

import java.util.Map;

/**
 * @author shiqian
 * @date 2021年09月29日 16:46
 * @description 驼峰和下划线转换
 **/
public class CamelLowerUnderScore {

    public static String camel2LowerUnderScore(String input){
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, input);
    }

    public static JSONObject camel2LowerUnderScore(Map<String, Object> jsonObject) {
        JSONObject result = new JSONObject(jsonObject.size());
        for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
            result.put(camel2LowerUnderScore(entry.getKey()), entry.getValue());
        }

        return result;
    }

}
