All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ly.doc.extension.json.PropertyNameHelper Maven / Gradle / Ivy

Go to download

Smart-doc is a tool that supports both JAVA RESTFUL API and Apache Dubbo RPC interface document generation.

There is a newer version: 3.0.5
Show newest version
package com.ly.doc.extension.json;

import java.util.List;

import com.ly.doc.constants.DocAnnotationConstants;
import com.power.common.util.StringUtil;
import com.thoughtworks.qdox.model.JavaAnnotation;

/**
 * @author xingzi
 * Date 2022/9/17 13:32
 */
public class PropertyNameHelper {

    public static final String JACKSON_LOWER_CAMEL_CASE = "lowercamel";
    public static final String JACKSON_UPPER_CAMEL_CASE = "uppercamel";
    public static final String JACKSON_SNAKE_CASE = "snake";
    public static final String JACKSON_UPPER_SNAKE_CASE = "uppersnake";
    public static final String JACKSON_LOWER_CASE = "lower";
    public static final String JACKSON_KEBAB_CASE = "kebab";
    public static final String JACKSON_LOWER_DOT_CASE = "lowerdot";


    private PropertyNameHelper() {
    }

    public static PropertyNamingStrategies.NamingBase translate(List javaAnnotations) {
        for (JavaAnnotation annotation : javaAnnotations) {
            String simpleAnnotationName = annotation.getType().getValue();
            //jackson
            if (DocAnnotationConstants.JSON_NAMING.equalsIgnoreCase(simpleAnnotationName)) {
                String value = annotation.getProperty("value").getParameterValue().toString().toLowerCase();
                return jackSonTranslate(value);
            }

        }
        return null;
    }

    private static PropertyNamingStrategies.NamingBase jackSonTranslate(String annotationValue) {
        if (StringUtil.isEmpty(annotationValue)) {
            return null;
        }
        if (annotationValue.contains(JACKSON_LOWER_CAMEL_CASE)) {
            return PropertyNamingStrategies.LOWER_CAMEL_CASE;
        }
        if (annotationValue.contains(JACKSON_UPPER_CAMEL_CASE)) {
            return PropertyNamingStrategies.UPPER_CAMEL_CASE;
        }
        if (annotationValue.contains(JACKSON_SNAKE_CASE)) {
            return PropertyNamingStrategies.SNAKE_CASE;
        }
        if (annotationValue.contains(JACKSON_UPPER_SNAKE_CASE)) {
            return PropertyNamingStrategies.UPPER_SNAKE_CASE;
        }
        if (annotationValue.contains(JACKSON_LOWER_CASE)) {
            return PropertyNamingStrategies.LOWER_CASE;
        }
        if (annotationValue.contains(JACKSON_KEBAB_CASE)) {
            return PropertyNamingStrategies.KEBAB_CASE;
        }
        if (annotationValue.contains(JACKSON_LOWER_DOT_CASE)) {
            return PropertyNamingStrategies.LOWER_DOT_CASE;
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy