类 JacksonUtils

java.lang.Object
com.alibaba.nacos.common.utils.JacksonUtils

public final class JacksonUtils extends Object
Json utils implement by Jackson.
作者:
liaochuntao
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static com.fasterxml.jackson.databind.JavaType
    construct java type -> Jackson Java Type.
    static com.fasterxml.jackson.databind.node.ArrayNode
    Create a new empty Jackson ArrayNode.
    static com.fasterxml.jackson.databind.node.ObjectNode
    Create a new empty Jackson ObjectNode.
    static void
    registerSubtype​(Class<?> clz, String type)
    Register sub type for child class.
    static String
    toJson​(Object obj)
    Object to json string.
    static byte[]
    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, Class<T> cls)
    Json string deserialize to Object.
    static <T> T
    toObj​(byte[] json, Type cls)
    Json string deserialize to Object.
    static <T> T
    toObj​(InputStream inputStream, Class<T> cls)
    Json string deserialize to Object.
    static <T> T
    toObj​(InputStream inputStream, Type type)
    Json string deserialize to Object.
    static com.fasterxml.jackson.databind.JsonNode
    toObj​(String json)
    Json string deserialize to Jackson JsonNode.
    static <T> T
    toObj​(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
    Json string deserialize to Object.
    static <T> T
    toObj​(String json, Class<T> cls)
    Json string deserialize to Object.
    static <T> T
    toObj​(String json, Type type)
    Json string deserialize to Object.
    static com.fasterxml.jackson.databind.JsonNode
    Parse object to Jackson JsonNode.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • JacksonUtils

      public JacksonUtils()
  • 方法详细资料

    • toJson

      public static String toJson(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(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, 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, 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(InputStream inputStream, 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(String json, 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(String json, 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(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(InputStream inputStream, 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(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(Class<?> clz, 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(Object obj)
      Parse object to Jackson JsonNode.
      参数:
      obj - object
      返回:
      JsonNode
    • constructJavaType

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