Class CosmosItemSerializer

java.lang.Object
com.azure.cosmos.CosmosItemSerializer

public abstract class CosmosItemSerializer extends Object
The CosmosItemSerializer allows customizing the serialization of Cosmos Items - either to transform payload (for example wrap/unwrap in custom envelopes) or use custom serialization settings or json serializer stacks.
  • Field Details

    • DEFAULT_SERIALIZER

      public static final CosmosItemSerializer DEFAULT_SERIALIZER
      Gets the default Cosmos item serializer. This serializer is used by default when no custom serializer is specified on request options or the CosmosClientBuilder
  • Constructor Details

    • CosmosItemSerializer

      protected CosmosItemSerializer()
      Used to instantiate subclasses
  • Method Details

    • serialize

      public abstract <T> Map<String,Object> serialize(T item)
      Used to serialize a POJO into a json tree
      Type Parameters:
      T - The type of the POJO
      Parameters:
      item - the POJO to be serialized
      Returns:
      the json tree that will be used as payload in Cosmos DB items
    • deserialize

      public abstract <T> T deserialize(Map<String,Object> jsonNodeMap, Class<T> classType)
      Used to deserialize the json tree stored in the Cosmos DB item as a POJO
      Type Parameters:
      T - The type of the POJO
      Parameters:
      jsonNodeMap - the json tree from the Cosmos DB item
      classType - The type of the POJO
      Returns:
      The deserialized POJO