类 JSONUtil


  • public abstract class JSONUtil
    extends Object
    JSON字符串序列化转换工具类
    作者:
    Ready
    • 字段详细资料

      • DEFAULT_SERIALIZER_FEATURES

        public static int DEFAULT_SERIALIZER_FEATURES
    • 构造器详细资料

      • JSONUtil

        public JSONUtil()
    • 方法详细资料

      • mergeFeatures

        public static int mergeFeatures​(int base,
                                        com.alibaba.fastjson.serializer.SerializerFeature extra)
      • mergeFeatures

        public static int mergeFeatures​(int base,
                                        com.alibaba.fastjson.serializer.SerializerFeature... extra)
      • encode

        public static String encode​(Object obj)
        将Java对象编码为JSON字符串。
        如果对象里存在为null的属性,则不包含在字符串中。
        参数:
        obj - 指定的任意对象
      • encodeKeepNull

        public static String encodeKeepNull​(Object obj)
        将Java对象编码为JSON字符串。
        值为null的属性也会保留并输出。
        参数:
        obj - 指定的任意对象
      • encodeWithExclude

        public static String encodeWithExclude​(Object obj,
                                               String... excludeProperties)
        将Java对象编码为JSON字符串
        参数:
        obj - 指定的任意对象
        excludeProperties - 需要排除的属性数组
      • serialize

        public static String serialize​(Object obj,
                                       String dateFormat,
                                       com.alibaba.fastjson.serializer.SerializeFilter... filters)
      • encodeWithInclude

        public static String encodeWithInclude​(Object obj,
                                               String... includeProperties)
        将Java对象编码为JSON字符串
        参数:
        obj - 指定的任意对象
        includeProperties - 需要排除的属性数组
      • encodeWithDateFormat

        public static String encodeWithDateFormat​(Object obj,
                                                  String pattern)
        将Java对象编码为JSON字符串,并以指定的格式化模式处理日期类型
        参数:
        obj - 指定的任意对象
        pattern - 指定的格式化字符串,例如"yyyy-MM-dd"
      • encodeWithReferenceDetect

        public static String encodeWithReferenceDetect​(Object obj)
        将Java对象编码为JSON字符串,它与encode()方法不同的是,它会进行循环引用检测。如果其中的多个元素或属性指向同一个对象引用,则后者将只输出对前者的引用表示
      • parse

        public static Object parse​(String text)
        将JSON字符串转为对应的JSONObject或JSONArray对象
        参数:
        text - 指定的JSON字符串
      • parseObject

        public static <T> T parseObject​(String text,
                                        Class<T> clazz)
        将JSON字符串转为指定类型的Java对象
        参数:
        text - 指定的JSON字符串
        clazz - 指定的类型
      • parseObject

        public static com.alibaba.fastjson.JSONObject parseObject​(String text)
        将JSON字符串转为JSONObject形式的对象(类似于增强型的 LinkedHashMap)
        参数:
        text - 指定的JSON字符串
      • parseArray

        public static com.alibaba.fastjson.JSONArray parseArray​(String text)
        将JSON字符串转为JSONArray形式的对象(类似于增强型的ArrayList)
        参数:
        text - 指定的JSON字符串
      • parseArray

        public static <T> List<T> parseArray​(String text,
                                             Class<T> clazz)
        将JSON字符串转为List形式的指定类型的对象集合
        参数:
        text - 指定的JSON字符串
        clazz - 指定的类型
      • serialize

        public static String serialize​(Object obj)
        将指定的Java对象序列化为JSON字符串
        参数:
        obj - 指定的对象
        从以下版本开始:
        0.1
      • deserialize

        public static <T> T deserialize​(String text)
        将指定的JSON字符串反序列化为指定的Java对象
        参数:
        text - 指定的JSON字符串
        从以下版本开始:
        0.1