Class ObjectSerializer

java.lang.Object
io.dapr.client.ObjectSerializer
Direct Known Subclasses:
ActorObjectSerializer, DefaultObjectSerializer

public class ObjectSerializer extends Object
Serializes and deserializes an internal object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final com.fasterxml.jackson.databind.ObjectMapper
    Shared Json serializer/deserializer as per Jackson's documentation.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default constructor to avoid class from being instantiated outside package but still inherited.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    deserialize(byte[] content, TypeRef<T> type)
    Deserializes the byte array into the original object.
    <T> T
    deserialize(byte[] content, Class<T> clazz)
    Deserializes the byte array into the original object.
    com.fasterxml.jackson.databind.JsonNode
    parseNode(byte[] content)
    Parses the JSON content into a node for fine-grained processing.
    byte[]
    Serializes a given state object into byte array.

    Methods inherited from class java.lang.Object

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

    • OBJECT_MAPPER

      protected static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
      Shared Json serializer/deserializer as per Jackson's documentation.
  • Constructor Details

    • ObjectSerializer

      protected ObjectSerializer()
      Default constructor to avoid class from being instantiated outside package but still inherited.
  • Method Details

    • serialize

      public byte[] serialize(Object state) throws IOException
      Serializes a given state object into byte array.
      Parameters:
      state - State object to be serialized.
      Returns:
      Array of bytes[] with the serialized content.
      Throws:
      IOException - In case state cannot be serialized.
    • deserialize

      public <T> T deserialize(byte[] content, TypeRef<T> type) throws IOException
      Deserializes the byte array into the original object.
      Type Parameters:
      T - Generic type of the object being deserialized.
      Parameters:
      content - Content to be parsed.
      type - Type of the object being deserialized.
      Returns:
      Object of type T.
      Throws:
      IOException - In case content cannot be deserialized.
    • deserialize

      public <T> T deserialize(byte[] content, Class<T> clazz) throws IOException
      Deserializes the byte array into the original object.
      Type Parameters:
      T - Generic type of the object being deserialized.
      Parameters:
      content - Content to be parsed.
      clazz - Type of the object being deserialized.
      Returns:
      Object of type T.
      Throws:
      IOException - In case content cannot be deserialized.
    • parseNode

      public com.fasterxml.jackson.databind.JsonNode parseNode(byte[] content) throws IOException
      Parses the JSON content into a node for fine-grained processing.
      Parameters:
      content - JSON content.
      Returns:
      JsonNode.
      Throws:
      IOException - In case content cannot be parsed.