Class Json


  • public class Json
    extends Object
    Json class to facilitate reading and writing json.
    • Method Detail

      • create

        public static Json create()
        Create a pre-configured ObjectMapper object.
        Returns:
        ObjectMapper object
      • withMapper

        public static Json withMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)
        Create an instance with a provided mapper.
        Parameters:
        mapper - objectmapper
        Returns:
        Json
      • toJson

        public String toJson​(Object value)
                      throws com.fasterxml.jackson.core.JsonProcessingException
        Serialize an object to a json string. Use when you don't know if object is serializable.
        Parameters:
        value - The object to serialize.
        Returns:
        The serialized object.
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
        See Also:
        toJson(Object)
      • toJsonUnchecked

        public String toJsonUnchecked​(Object value)
        Serialize an object to a json string. Use when object is expected to be json serializable.
        Parameters:
        value - The object to serialize.
        Returns:
        The serialized object.
        See Also:
        toJson(Object)
      • fromJson

        public <T> T fromJson​(String content,
                              Class<T> clazz)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        content - The string to de-serialize.
        clazz - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJson

        public <T> T fromJson​(String content,
                              com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        content - The string to de-serialize.
        typeReference - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJson

        public <T> T fromJson​(String content,
                              com.fasterxml.jackson.databind.JavaType javaType)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        content - The string to de-serialize.
        javaType - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJson

        public <T> T fromJson​(byte[] bytes,
                              Class<T> clazz)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        bytes - The string to de-serialize.
        clazz - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJson

        public <T> T fromJson​(byte[] bytes,
                              com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        bytes - The string to de-serialize.
        typeReference - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJson

        public <T> T fromJson​(byte[] bytes,
                              com.fasterxml.jackson.databind.JavaType javaType)
                       throws IOException
        De-serialize an object from a json string. Use when you don't know if object is serializable.
        Parameters:
        bytes - The string to de-serialize.
        javaType - The object to de-serialize to.
        Returns:
        The serialized object.
        Throws:
        IOException
      • fromJsonUnchecked

        public <T> T fromJsonUnchecked​(String content,
                                       Class<T> clazz)
        De-serialize an object from a json string. Use when know the object is serializable.
        Parameters:
        content - The string to de-serialize.
        clazz - The object to de-serialize to.
        Returns:
        The serialized object.
        See Also:
        fromJsonUnchecked(String, Class)
      • fromJsonUnchecked

        public <T> T fromJsonUnchecked​(String content,
                                       com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
        De-serialize an object from a json string. Use when know the object is serializable.
        Parameters:
        content - The string to de-serialize.
        typeReference - The object to de-serialize to.
        Returns:
        The serialized object.
        See Also:
        fromJson(String, TypeReference)
      • fromJsonUncheckedNotNull

        public <T> T fromJsonUncheckedNotNull​(String content,
                                              Class<T> clazz)
        De-serialize an object from a json string. Use when know the object is serializable.
        Parameters:
        content - The string to de-serialize.
        clazz - The object to de-serialize to.
        Returns:
        The serialized object.
        See Also:
        fromJsonUnchecked(String, Class)
      • fromJsonUncheckedNotNull

        public <T> T fromJsonUncheckedNotNull​(String content,
                                              com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
        De-serialize an object from a json string. Use when know the object is serializable.
        Parameters:
        content - The string to de-serialize.
        typeReference - The object to de-serialize to.
        Returns:
        The serialized object.
        See Also:
        fromJson(String, TypeReference)