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
    Serialize the object to JSON
    byte[]
    Serialize the object to 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