类 JacksonUtils


  • public final class JacksonUtils
    extends java.lang.Object
    Json utils implement by Jackson.
    作者:
    liaochuntao
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      (专用程序包) static com.fasterxml.jackson.databind.ObjectMapper mapper  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static com.fasterxml.jackson.databind.JavaType constructJavaType​(java.lang.reflect.Type type)
      construct java type -> Jackson Java Type.
      static com.fasterxml.jackson.databind.node.ArrayNode createEmptyArrayNode()
      Create a new empty Jackson ArrayNode.
      static com.fasterxml.jackson.databind.node.ObjectNode createEmptyJsonNode()
      Create a new empty Jackson ObjectNode.
      static void registerSubtype​(java.lang.Class<?> clz, java.lang.String type)
      Register sub type for child class.
      static java.lang.String toJson​(java.lang.Object obj)
      Object to json string.
      static byte[] toJsonBytes​(java.lang.Object obj)
      Object to json string byte array.
      static <T> T toObj​(byte[] json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      Json string deserialize to Object.
      static <T> T toObj​(byte[] json, java.lang.Class<T> cls)
      Json string deserialize to Object.
      static <T> T toObj​(byte[] json, java.lang.reflect.Type cls)
      Json string deserialize to Object.
      static <T> T toObj​(java.io.InputStream inputStream, java.lang.Class<T> cls)
      Json string deserialize to Object.
      static <T> T toObj​(java.io.InputStream inputStream, java.lang.reflect.Type type)
      Json string deserialize to Object.
      static com.fasterxml.jackson.databind.JsonNode toObj​(java.lang.String json)
      Json string deserialize to Jackson JsonNode.
      static <T> T toObj​(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      Json string deserialize to Object.
      static <T> T toObj​(java.lang.String json, java.lang.Class<T> cls)
      Json string deserialize to Object.
      static <T> T toObj​(java.lang.String json, java.lang.reflect.Type type)
      Json string deserialize to Object.
      static com.fasterxml.jackson.databind.JsonNode transferToJsonNode​(java.lang.Object obj)
      Parse object to Jackson JsonNode.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • mapper

        static com.fasterxml.jackson.databind.ObjectMapper mapper
    • 构造器详细资料

      • JacksonUtils

        public JacksonUtils()
    • 方法详细资料

      • toJson

        public static java.lang.String toJson​(java.lang.Object obj)
        Object to json string.
        参数:
        obj - obj
        返回:
        json string
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosSerializationException - if transfer failed
      • toJsonBytes

        public static byte[] toJsonBytes​(java.lang.Object obj)
        Object to json string byte array.
        参数:
        obj - obj
        返回:
        json string byte array
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosSerializationException - if transfer failed
      • toObj

        public static <T> T toObj​(byte[] json,
                                  java.lang.Class<T> cls)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string
        cls - class of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(byte[] json,
                                  java.lang.reflect.Type cls)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string
        cls - Type of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(java.io.InputStream inputStream,
                                  java.lang.Class<T> cls)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        inputStream - json string input stream
        cls - class of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(byte[] json,
                                  com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string byte array
        typeReference - TypeReference of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(java.lang.String json,
                                  java.lang.Class<T> cls)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string
        cls - class of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(java.lang.String json,
                                  java.lang.reflect.Type type)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string
        type - Type of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(java.lang.String json,
                                  com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        json - json string
        typeReference - TypeReference of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static <T> T toObj​(java.io.InputStream inputStream,
                                  java.lang.reflect.Type type)
        Json string deserialize to Object.
        类型参数:
        T - General type
        参数:
        inputStream - json string input stream
        type - Type of object
        返回:
        object
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • toObj

        public static com.fasterxml.jackson.databind.JsonNode toObj​(java.lang.String json)
        Json string deserialize to Jackson JsonNode.
        参数:
        json - json string
        返回:
        JsonNode
        抛出:
        com.alibaba.nacos.api.exception.runtime.NacosDeserializationException - if deserialize failed
      • registerSubtype

        public static void registerSubtype​(java.lang.Class<?> clz,
                                           java.lang.String type)
        Register sub type for child class.
        参数:
        clz - child class
        type - type name of child class
      • createEmptyJsonNode

        public static com.fasterxml.jackson.databind.node.ObjectNode createEmptyJsonNode()
        Create a new empty Jackson ObjectNode.
        返回:
        ObjectNode
      • createEmptyArrayNode

        public static com.fasterxml.jackson.databind.node.ArrayNode createEmptyArrayNode()
        Create a new empty Jackson ArrayNode.
        返回:
        ArrayNode
      • transferToJsonNode

        public static com.fasterxml.jackson.databind.JsonNode transferToJsonNode​(java.lang.Object obj)
        Parse object to Jackson JsonNode.
        参数:
        obj - object
        返回:
        JsonNode
      • constructJavaType

        public static com.fasterxml.jackson.databind.JavaType constructJavaType​(java.lang.reflect.Type type)
        construct java type -> Jackson Java Type.
        参数:
        type - java type
        返回:
        JavaType JavaType