Skip to content

struct Athena::Serializer::Bundle
inherits Athena::DependencyInjection::AbstractBundle #

Integrates the Serializer component with the dependency injection component, such as within an Athena Framework application.

Require athena-serializer/bundle to register the bundle; it does not require any configuration:

require "athena"
require "athena-serializer/bundle"

The bundle registers the serializer service, which may be injected via ASR::SerializerInterface:

@[ADI::Register]
class ArticleExporter
  def initialize(@serializer : ASR::SerializerInterface); end

  def export(article : Article) : String
    @serializer.serialize article, :yaml
  end
end

When registered, the framework also uses it to serialize the data returned from controller actions, and to deserialize request bodies into ASR::Serializable types.