类 JsonUtils


  • public final class JsonUtils
    extends Object
    通用Json工具类
    作者:
    woodwhales
    • 方法详细资料

      • toJson

        public static String toJson​(Object object)
        将Java对象转成Json,约束规则JsonInclude.Include.NON_EMPTY
        参数:
        object - object 对象
        返回:
        json 字符串
      • toJson

        public static String toJson​(Object object,
                                    com.fasterxml.jackson.annotation.JsonInclude.Include include)
        将Java对象转成Json,默认约束规则JsonInclude.Include.NON_EMPTY
        参数:
        object - object 对象
        include - JsonInclude.Include
        返回:
        json字符串
      • toObject

        public static <T> T toObject​(String json,
                                     Class<T> clazz)
        将Json转成Java对象
        类型参数:
        T - 返回结果类型
        参数:
        json - json 字符串
        clazz - Class对象
        返回:
        返回对象
      • toTypeReference

        public static <T> T toTypeReference​(String json,
                                            com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
        将Json转成Java对象
        类型参数:
        T - TypeReference泛型中的泛型
        参数:
        json - json 字符串
        typeReference - TypeReference
        返回:
        TypeReference泛型中的对象
      • toJavaType

        public static <T> T toJavaType​(String json,
                                       com.fasterxml.jackson.databind.JavaType javaType)
        将Json转成Java对象
        类型参数:
        T - JavaType的泛型
        参数:
        json - json 字符串
        javaType - JavaType
        返回:
        JavaType的泛型对象