类 JdplwJsonUtils

java.lang.Object
javabase.lorenwang.dataparse.JdplwJsonUtils

public class JdplwJsonUtils
extends Object
Json工具类
作者:
yynie
  • 字段详细资料

    • EMPTY_JSON

      public static final String EMPTY_JSON
      另请参阅:
      常量字段值
    • EMPTY_JSON_ARRAY

      public static final String EMPTY_JSON_ARRAY
      另请参阅:
      常量字段值
    • DEFAULT_DATE_PATTERN

      public static final String DEFAULT_DATE_PATTERN
      另请参阅:
      常量字段值
    • DEFAULT_EXCLUDES_FIELDS_WITHOUT_EXPOSE

      public static final boolean DEFAULT_EXCLUDES_FIELDS_WITHOUT_EXPOSE
      另请参阅:
      常量字段值
    • SINCE_VERSION_10

      public static final double SINCE_VERSION_10
      另请参阅:
      常量字段值
    • SINCE_VERSION_11

      public static final double SINCE_VERSION_11
      另请参阅:
      常量字段值
    • SINCE_VERSION_12

      public static final double SINCE_VERSION_12
      另请参阅:
      常量字段值
  • 构造器详细资料

    • JdplwJsonUtils

      public JdplwJsonUtils()
  • 方法详细资料

    • toJson

      public static String toJson​(Object target)
      格式化成json字符串
      参数:
      target - 任意类型实体
      返回:
      字符串
    • toJson

      public static String toJson​(Object target, Type targetType)
    • toJson

      public static String toJson​(Object target, Type targetType, Double version)
    • toJson

      public static String toJson​(Object target, Type targetType, boolean excludesFieldsWithoutExpose)
    • toJson

      public static String toJson​(Object target, Type targetType, Double version, boolean excludesFieldsWithoutExpose)
    • toJson

      public static String toJson​(Object target, boolean excludesFieldsWithoutExpose)
    • toJson

      public static String toJson​(Object target, Type targetType, boolean isSerializeNulls, Double version, String datePattern, boolean excludesFieldsWithoutExpose)
      将给定的目标对象根据所指定的条件参数转换成JSON格式的字符串
      参数:
      target - 目标对象
      targetType - 目标对象的类型
      isSerializeNulls - 是否序列化Null值字段
      version - 字段的版本号注解
      datePattern - 日期字段的格式化模式
      excludesFieldsWithoutExpose - 是否排除未标注@Expose注解的字段
      返回:
      目标对象的JSON格式的字符串
    • toJson

      public static String toJson​(Object target, Type targetType, com.google.gson.GsonBuilder builder)
      将给定的目标对象根据所指定的条件参数转换成JSON格式的字符串。 该方法转换发生错误时,不会抛出任何异常。若发生错误时,对象返回"{}",集合或数组对象返回 "[]", 其本基本类型,返回相应的基本值
      参数:
      target - 目标对象。
      targetType - 目标对象的类型
      builder - 可定制的Gson构建器
      返回:
      目标对象的JSON格式的字符串
    • fromJson

      public static <T> T fromJson​(String json, Class<T> cls)
    • fromJson

      public static <T> T fromJson​(String json, com.google.gson.reflect.TypeToken<T> token)
      格式化json字符串
      类型参数:
      T - 泛型
      参数:
      json - 字符串
      token - 特殊类型
      返回:
      特殊类型实体
    • fromJson

      public static <T> T fromJson​(String json, Class<T> cls, String datePattern)
      将给定的JSON字符串转换成指定的类型对象
      类型参数:
      T - 泛型
      参数:
      json - 给定的JSON字符串
      cls - 要转换的目标类
      datePattern - 日期格式
      返回:
      给定的JSON字符串表示的指定的类型对象
    • fromJson

      public static <T> T fromJson​(String json, com.google.gson.reflect.TypeToken<T> token, String datePattern)
      将给定的JSON字符串转换成指定的类型对象
      类型参数:
      T - 泛型
      参数:
      json - 给定的JSON字符串
      token - 类型
      datePattern - 日期格式
      返回:
      给定的JSON字符串表示的指定的类型对象
    • fromJson

      public static <T> T fromJson​(Map<String,​Object> map, Class<T> cls)
      将Map转化为Json
      类型参数:
      T - 实体类泛型
      参数:
      map - 将Map转化为Json
      cls - 要转换的实体类class
      返回:
      实体类
    • fromJsonArray

      public static <T> List<T> fromJsonArray​(String json, Class<T> cls)
      格式json集合
      类型参数:
      T - 泛型
      参数:
      json - json字符串
      cls - 集合内实体cls
      返回:
      集合
    • fromJsonArray2

      public static <T> List<T> fromJsonArray2​(com.google.gson.JsonArray jsonArray, Class<T> cls)
      格式化json集合
      类型参数:
      T - 泛型
      参数:
      jsonArray - json集合
      cls - 集合内实体cls
      返回:
      集合