Package cn.toint.oktool.util
Class JacksonUtil
java.lang.Object
cn.toint.oktool.util.JacksonUtil
- Author:
- Toint
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TconvertValue(Object fromValue, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef) 转换操作为深拷贝static <T> TconvertValue(Object fromValue, Class<T> toValueType) 转换操作为深拷贝static com.fasterxml.jackson.databind.node.ArrayNodestatic com.fasterxml.jackson.databind.ModulecreateLocalDateTimeModule(String pattern, ZoneId zoneId) 创建LocalDateTime序列化与反序列化配置模块static com.fasterxml.jackson.databind.Module创建Long序列化配置模块static com.fasterxml.jackson.databind.node.ObjectNodestatic com.fasterxml.jackson.databind.Module创建Long安全序列化配置模块static <T,R> String getAlias(cn.hutool.v7.core.func.SerFunction<T, R> func) 获取属性别名static String获取属性别名static <T extends Serializable>
StringgetAlias(T func) 获取属性别名static IntegergetInteger(com.fasterxml.jackson.databind.JsonNode jsonNode, String fieldName) static <T,R> com.fasterxml.jackson.annotation.JsonProperty getJsonProperty(cn.hutool.v7.core.func.SerFunction<T, R> func) 获取@JsonPropertystatic com.fasterxml.jackson.annotation.JsonPropertygetJsonProperty(Class<?> beanClass, String fieldName) 获取@JsonPropertystatic <T extends Serializable>
com.fasterxml.jackson.annotation.JsonPropertygetJsonProperty(T func) 获取@JsonPropertystatic com.fasterxml.jackson.databind.ObjectMapperstatic Stringstatic booleanisEmpty(com.fasterxml.jackson.databind.JsonNode value) static booleanisNotEmpty(com.fasterxml.jackson.databind.JsonNode value) static booleanisNotNull(com.fasterxml.jackson.databind.JsonNode value) static booleanisNull(com.fasterxml.jackson.databind.JsonNode value) static com.fasterxml.jackson.databind.ObjectMapperstatic voidobjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) static com.fasterxml.jackson.databind.node.ObjectNodestatic com.fasterxml.jackson.databind.node.ObjectNodeofObjectNode(String key, Object value) static com.fasterxml.jackson.databind.JsonNodestatic <T> Tstatic <T> Tstatic voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) static <T> TtreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef) static <T> TtreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.databind.JavaType valueType) static <T> TtreeToValue(com.fasterxml.jackson.core.TreeNode n, Class<T> valueType) static com.fasterxml.jackson.databind.JsonNodetryReadTree(String content) static <T> TtryReadValue(String content, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) static <T> TtryReadValue(String content, Class<T> valueType) static <T> TtryTreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef) static <T> TtryTreeToValue(com.fasterxml.jackson.core.TreeNode n, com.fasterxml.jackson.databind.JavaType valueType) static <T> TtryTreeToValue(com.fasterxml.jackson.core.TreeNode n, Class<T> valueType) static byte[]tryWriteValueAsBytes(Object value) static StringtryWriteValueAsString(Object value) static <T extends com.fasterxml.jackson.databind.JsonNode>
TvalueToTree(Object value) 转换操作为深拷贝static byte[]writeValueAsBytes(Object value) static StringwriteValueAsString(Object value)
-
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
-
readValue
public static <T> T readValue(String content, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) -
tryReadValue
-
tryReadValue
public static <T> T tryReadValue(String content, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) -
writeValueAsString
-
tryWriteValueAsString
-
writeValueAsBytes
-
tryWriteValueAsBytes
-
valueToTree
转换操作为深拷贝 -
convertValue
转换操作为深拷贝 -
convertValue
public static <T> T convertValue(Object fromValue, com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef) 转换操作为深拷贝 -
getAlias
获取属性别名- Parameters:
func- Lambda- Returns:
- 字段别名
-
getAlias
获取属性别名- Parameters:
func- Lambda- Returns:
- 字段别名
-
getAlias
获取属性别名- Parameters:
beanClass- beanClassfieldName- 字段名称- 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(cn.hutool.v7.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- beanClassfieldName- 字段名称- Returns:
- JsonProperty
-
tryReadTree
-
readTree
-
createArrayNode
public static com.fasterxml.jackson.databind.node.ArrayNode createArrayNode() -
createObjectNode
public static com.fasterxml.jackson.databind.node.ObjectNode createObjectNode() -
treeToValue
-
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
-
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
-
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:sszoneId- 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()- Returns:
- 将
Module注册成 springboot bean, springboot 会将其加入 springboot 默认的ObjectMapper中
-
getString
-
getInteger
-