java.lang.Object
dk.cloudcreate.essentials.components.foundation.json.JacksonJSONSerializer
All Implemented Interfaces:
JSONSerializer

public class JacksonJSONSerializer extends Object implements JSONSerializer
Jackson ObjectMapper based JSONSerializer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.fasterxml.jackson.databind.ObjectMapper
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    JacksonJSONSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    deserialize(byte[] json, Class<T> javaType)
    Deserialize the payload in the json parameter into the Java type specified by the javaType parameter
    <T> T
    deserialize(byte[] json, String javaType)
    Deserialize the payload in the json parameter into the Java type specified by the Fully Qualified Class Name contained in the javaType parameter
    <T> T
    deserialize(String json, Class<T> javaType)
    Deserialize the payload in the json parameter into the Java type specified by the javaType parameter
    <T> T
    deserialize(String json, String javaType)
    Deserialize the payload in the json parameter into the Java type specified by the Fully Qualified Class Name contained in the javaType parameter
    Get the ClassLoader used for serializing to JSON and deserializing from JSON
    Note: MUST not be null
    com.fasterxml.jackson.databind.ObjectMapper
    Direct access to the internal ObjectMapper used by the JacksonJSONSerializer (or subclasses)
    Serialize the object to JSON
    byte[]
    Serialize the object to JSON
    void
    Set the ClassLoader used for serializing to JSON and deserializing from JSON.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • objectMapper

      protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
  • Constructor Details

    • JacksonJSONSerializer

      public JacksonJSONSerializer(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • serialize

      public String serialize(Object obj)
      Description copied from interface: JSONSerializer
      Serialize the object to JSON
      Specified by:
      serialize in interface JSONSerializer
      Parameters:
      obj - the object to serialize
      Returns:
      the serialized json payload as a String
    • serializeAsBytes

      public byte[] serializeAsBytes(Object obj)
      Description copied from interface: JSONSerializer
      Serialize the object to JSON
      Specified by:
      serializeAsBytes in interface JSONSerializer
      Parameters:
      obj - the object to serialize
      Returns:
      the serialized json payload as a byte[]
    • deserialize

      public <T> T deserialize(String json, String javaType)
      Description copied from interface: JSONSerializer
      Deserialize the payload in the json parameter into the Java type specified by the Fully Qualified Class Name contained in the javaType parameter
      Specified by:
      deserialize in interface JSONSerializer
      Type Parameters:
      T - the corresponding Java type
      Parameters:
      json - the json payload
      javaType - the Fully Qualified Class Name for the Java type that the json payload should be deserialized into
      Returns:
      the deserialized json payload
    • deserialize

      public <T> T deserialize(String json, Class<T> javaType)
      Description copied from interface: JSONSerializer
      Deserialize the payload in the json parameter into the Java type specified by the javaType parameter
      Specified by:
      deserialize in interface JSONSerializer
      Type Parameters:
      T - the corresponding Java type
      Parameters:
      json - the json payload
      javaType - the Java type that the json payload should be deserialized into
      Returns:
      the deserialized json payload
    • deserialize

      public <T> T deserialize(byte[] json, String javaType)
      Description copied from interface: JSONSerializer
      Deserialize the payload in the json parameter into the Java type specified by the Fully Qualified Class Name contained in the javaType parameter
      Specified by:
      deserialize in interface JSONSerializer
      Type Parameters:
      T - the corresponding Java type
      Parameters:
      json - the json payload
      javaType - the Fully Qualified Class Name for the Java type that the json payload should be deserialized into
      Returns:
      the deserialized json payload
    • deserialize

      public <T> T deserialize(byte[] json, Class<T> javaType)
      Description copied from interface: JSONSerializer
      Deserialize the payload in the json parameter into the Java type specified by the javaType parameter
      Specified by:
      deserialize in interface JSONSerializer
      Type Parameters:
      T - the corresponding Java type
      Parameters:
      json - the json payload
      javaType - the Java type that the json payload should be deserialized into
      Returns:
      the deserialized json payload
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: JSONSerializer
      Get the ClassLoader used for serializing to JSON and deserializing from JSON
      Note: MUST not be null
      Specified by:
      getClassLoader in interface JSONSerializer
      Returns:
      the ClassLoader used for serializing to JSON and deserializing from JSON
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Description copied from interface: JSONSerializer
      Set the ClassLoader used for serializing to JSON and deserializing from JSON. This is e.g. required to support SpringBoot DevTools
      Specified by:
      setClassLoader in interface JSONSerializer
      Parameters:
      classLoader - the ClassLoader used for serializing to JSON and deserializing from JSON
    • getObjectMapper

      public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Direct access to the internal ObjectMapper used by the JacksonJSONSerializer (or subclasses)
      Returns:
      the internal ObjectMapper