Class JacksonUtil

java.lang.Object
cn.toint.oktool.util.JacksonUtil

public class JacksonUtil extends Object
Author:
Toint
  • Constructor Details

    • JacksonUtil

      public JacksonUtil()
  • Method Details

    • getObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • setObjectMapper

      public static void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • objectMapper

      public static void objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • objectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper objectMapper()
    • readValue

      public static <T> T readValue(String content, Class<T> valueType)
    • readValue

      public static <T> T readValue(String content, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    • tryReadValue

      public static <T> T tryReadValue(String content, Class<T> valueType)
    • tryReadValue

      public static <T> T tryReadValue(String content, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    • writeValueAsString

      public static String writeValueAsString(Object value)
    • tryWriteValueAsString

      public static String tryWriteValueAsString(Object value)
    • writeValueAsBytes

      public static byte[] writeValueAsBytes(Object value)
    • tryWriteValueAsBytes

      public static byte[] tryWriteValueAsBytes(Object value)
    • valueToTree

      public static <T extends com.fasterxml.jackson.databind.JsonNode> T valueToTree(Object value)
      转换操作为深拷贝
    • convertValue

      public static <T> T convertValue(Object fromValue, Class<T> toValueType)
      转换操作为深拷贝
    • convertValue

      public static <T> T convertValue(Object fromValue, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
      转换操作为深拷贝
    • getAlias

      public static <T extends Serializable> String getAlias(T func)
      获取属性别名
      Parameters:
      func - Lambda
      Returns:
      字段别名
    • getAlias

      public static <T, R> String getAlias(org.dromara.hutool.core.func.SerFunction<T,R> func)
      获取属性别名
      Parameters:
      func - Lambda
      Returns:
      字段别名
    • getAlias

      public static String getAlias(Class<?> beanClass, String fieldName)
      获取属性别名
      Parameters:
      beanClass - beanClass
      fieldName - 字段名称
      Returns:
      字段别名
    • getJsonProperty

      public static <T extends Serializable> com.fasterxml.jackson.annotation.JsonProperty getJsonProperty(T func)
      获取@JsonProperty
      Parameters:
      func - Lambda
      Returns:
      JsonProperty
    • getJsonProperty

      public static <T, R> com.fasterxml.jackson.annotation.JsonProperty getJsonProperty(org.dromara.hutool.core.func.SerFunction<T,R> func)
      获取@JsonProperty
      Parameters:
      func - Lambda
      Returns:
      JsonProperty
    • getJsonProperty

      public static com.fasterxml.jackson.annotation.JsonProperty getJsonProperty(Class<?> beanClass, String fieldName)
      获取@JsonProperty
      Parameters:
      beanClass - beanClass
      fieldName - 字段名称
      Returns:
      JsonProperty
    • tryReadTree

      public static com.fasterxml.jackson.databind.JsonNode tryReadTree(String content)
    • readTree

      public static com.fasterxml.jackson.databind.JsonNode readTree(String content)
    • createArrayNode

      public static com.fasterxml.jackson.databind.node.ArrayNode createArrayNode()
    • createObjectNode

      public static com.fasterxml.jackson.databind.node.ObjectNode createObjectNode()
    • treeToValue

      public static <T> T treeToValue(com.fasterxml.jackson.core.TreeNode n, Class<T> valueType)
    • treeToValue

      public static <T> T treeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
    • treeToValue

      public static <T> T treeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.databind.JavaType valueType)
    • tryTreeToValue

      public static <T> T tryTreeToValue(com.fasterxml.jackson.core.TreeNode n, Class<T> valueType)
    • tryTreeToValue

      public static <T> T tryTreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
    • tryTreeToValue

      public static <T> T tryTreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.databind.JavaType valueType)
    • ofObjectNode

      public static com.fasterxml.jackson.databind.node.ObjectNode ofObjectNode(String key, Object value)
    • ofObjectNode

      public static com.fasterxml.jackson.databind.node.ObjectNode ofObjectNode()
    • isNull

      public static boolean isNull(com.fasterxml.jackson.databind.JsonNode value)
    • isNotNull

      public static boolean isNotNull(com.fasterxml.jackson.databind.JsonNode value)
    • isEmpty

      public static boolean isEmpty(com.fasterxml.jackson.databind.JsonNode value)
    • isNotEmpty

      public static boolean isNotEmpty(com.fasterxml.jackson.databind.JsonNode value)
    • createLocalDateTimeModule

      public static com.fasterxml.jackson.databind.Module createLocalDateTimeModule(@Nullable String pattern, @Nullable ZoneId zoneId)
      创建 LocalDateTime 序列化与反序列化配置模块
      Parameters:
      pattern - pattern, 不传默认: yyyy-MM-dd HH:mm:ss
      zoneId - zoneId, 不传默认: ZoneId.of("Asia/Shanghai")
      Returns:
      Module 注册成 springboot bean, springboot 会将其加入 springboot 默认的 ObjectMapper
    • createLongModule

      public static com.fasterxml.jackson.databind.Module createLongModule()
      创建 Long 序列化配置模块
      Returns:
      Module 注册成 springboot bean, springboot 会将其加入 springboot 默认的 ObjectMapper
    • createSafeLongModule

      public static com.fasterxml.jackson.databind.Module createSafeLongModule()
      创建 Long 安全序列化配置模块

      当数字超过 JavaScript 安全范围, 会导致精度丢失

      本模块会判断 Long 值是否超过安全范围, 超过则序列化为 String, 否则保持 Number

      Returns:
      Module 注册成 springboot bean, springboot 会将其加入 springboot 默认的 ObjectMapper