Class KiotaSerialization

java.lang.Object
com.microsoft.kiota.serialization.KiotaSerialization

public final class KiotaSerialization extends Object
Helper methods for serialization of kiota models
  • Method Details

    • serializeAsStream

      @Nonnull public static <T extends Parsable> InputStream serializeAsStream(@Nonnull String contentType, @Nonnull T value) throws IOException
      Serializes the given value to a stream
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      value - the value to serialize
      Returns:
      the serialized value as a stream
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsStream

      @Nonnull public static <T extends Parsable> InputStream serializeAsStream(@Nonnull String contentType, @Nonnull T value, boolean serializeOnlyChangedValues) throws IOException
      Serializes the given value to a stream and configures returned values by the backing store if available
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      value - the value to serialize
      serializeOnlyChangedValues - whether to serialize all values in value if value is a BackedModel
      Returns:
      the serialized value as a stream
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsString

      @Nonnull public static <T extends Parsable> String serializeAsString(@Nonnull String contentType, @Nonnull T value) throws IOException
      Serializes the given value to a string
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      value - the value to serialize
      Returns:
      the serialized value as a string
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsString

      @Nonnull public static <T extends Parsable> String serializeAsString(@Nonnull String contentType, @Nonnull T value, boolean serializeOnlyChangedValues) throws IOException
      Serializes the given value to a string
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      value - the value to serialize
      serializeOnlyChangedValues - whether to serialize all values in value if value is a BackedModel
      Returns:
      the serialized value as a string
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsStream

      @Nonnull public static <T extends Parsable> InputStream serializeAsStream(@Nonnull String contentType, @Nonnull Iterable<T> values) throws IOException
      Serializes the given value to a stream
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      values - the values to serialize
      Returns:
      the serialized value as a stream
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsStream

      @Nonnull public static <T extends Parsable> InputStream serializeAsStream(@Nonnull String contentType, @Nonnull Iterable<T> values, boolean serializeOnlyChangedValues) throws IOException
      Serializes the given value to a stream
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      values - the values to serialize
      serializeOnlyChangedValues - whether to serialize all values in value if value is a BackedModel
      Returns:
      the serialized value as a stream
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsString

      @Nonnull public static <T extends Parsable> String serializeAsString(@Nonnull String contentType, @Nonnull Iterable<T> values) throws IOException
      Serializes the given value to a string
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      values - the values to serialize
      Returns:
      the serialized value as a string
      Throws:
      IOException - when the stream cannot be closed or read.
    • serializeAsString

      @Nonnull public static <T extends Parsable> String serializeAsString(@Nonnull String contentType, @Nonnull Iterable<T> values, boolean serializeOnlyChangedValues) throws IOException
      Serializes the given value to a string
      Type Parameters:
      T - the type of the value to serialize
      Parameters:
      contentType - the content type to use for serialization
      values - the values to serialize
      serializeOnlyChangedValues - whether to serialize all values in value if value is a BackedModel
      Returns:
      the serialized value as a string
      Throws:
      IOException - when the stream cannot be closed or read.
    • deserialize

      @Nonnull public static <T extends Parsable> T deserialize(@Nonnull String contentType, @Nonnull InputStream stream, @Nonnull ParsableFactory<T> parsableFactory)
      Deserializes the given stream to a model object
      Type Parameters:
      T - the type of the value to deserialize
      Parameters:
      contentType - the content type to use for deserialization
      stream - the stream to deserialize
      parsableFactory - the factory to use for creating the model object
      Returns:
      the deserialized value
    • deserialize

      @Nonnull public static <T extends Parsable> T deserialize(@Nonnull String contentType, @Nonnull String value, @Nonnull ParsableFactory<T> parsableFactory) throws IOException
      Deserializes the given string to a model object
      Type Parameters:
      T - the type of the value to deserialize
      Parameters:
      contentType - the content type to use for deserialization
      value - the string to deserialize
      parsableFactory - the factory to use for creating the model object
      Returns:
      the deserialized value
      Throws:
      IOException - when the stream cannot be closed or read.
    • deserializeCollection

      @Nonnull public static <T extends Parsable> List<T> deserializeCollection(@Nonnull String contentType, @Nonnull String value, @Nonnull ParsableFactory<T> parsableFactory) throws IOException
      Deserializes the given string to a collection of model objects
      Type Parameters:
      T - the type of the value to deserialize
      Parameters:
      contentType - the content type to use for deserialization
      value - the string to deserialize
      parsableFactory - the factory to use for creating the model object
      Returns:
      the deserialized value
      Throws:
      IOException - when the stream cannot be closed or read.
    • deserializeCollection

      @Nonnull public static <T extends Parsable> List<T> deserializeCollection(@Nonnull String contentType, @Nonnull InputStream stream, @Nonnull ParsableFactory<T> parsableFactory)
      Deserializes the given stream to a collection of model objects
      Type Parameters:
      T - the type of the value to deserialize
      Parameters:
      contentType - the content type to use for deserialization
      stream - the stream to deserialize
      parsableFactory - the factory to use for creating the model object
      Returns:
      the deserialized value