anchor.diff:  # => "bar"
   ```
   
  -<% in_version_above('0.39.0') do %>
  +Another way to achive that could be define your own [custom mapper & transformation](/docs/mapping_serialization/#custom-mapper).
  +
   Additionally, if you are using Postgres, you can configure the migration
   to use JSON or JSONB data types for the `data` and `metadata` fields by
   passing in a `--data-type` to the generator
  
positive.code: ```console
  $ rails generate rails_event_store_active_record:migration --data-type=jsonb
  ```
  <% end %>
  
  ## Configuring a different mapper
  
  
negative.code:     - `events_class_remapping:` - which can be used for mapping old event names to new ones after you refactored your codebase.
  - [`RubyEventStore::Mappers::Protobuf`](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/protobuf.rb)
    - works with Ruby classes generated by `google-protobuf` gem
  - [`RubyEventStore::Mappers::NullMapper`](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/null_mapper.rb)
    - works with `RubyEventStore::Event` or `RailsEventStore::Event`
    - no transformations, useful in tests
  - [`RubyEventStore::Mappers::EncryptionMapper`](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/encryption_mapper.rb)
    - works with `RubyEventStore::Event` or `RailsEventStore::Event`
    - constructor takes named arguments:
      - `key_repository` - which is responsible for providing encryption keys used to encrypt/descrypt payload by encryption transformation
      - `serializer:` (described above)
  
  ## Custom mapper
  
  Mapper is defined as a pipeline of transformations that transforms domain event object into serialized record and back from serialized recoed to domain event. I.e. `DefaultMapper` is implemented as a set of 3 transformations. Transformations works on [transformation item](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/transformation/item.rb) objects, it is given to transformation methods (it is expected that `load` & `dump` methods are implemented) and it is result of any transformation performed. Except transformations each pipeline mapper needs to be given 2 edge transformations:
  
  * to transform domain event to/from transformation item (default [`RubyEventStore::Mappers::Transformation::DomainEvent`](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/transformation/domain_event.rb))
  * to transform serialized record to/from transformation item (default [`RubyEventStore::Mappers::Transformation::SerializedRecord`](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/transformation/serialized_record.rb))
  
  
  Extended implementation of [DefaultMapper](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/default.rb) with explicit default arguments:
  
  ```ruby
  module RubyEventStore
    module Mappers
      class Default < PipelineMapper
        def initialize(serializer: YAML, events_class_remapping: {})
          super(Pipeline.new(
            to_domain_event: Transformation::DomainEvent.new,
            to_serialized_record: Transformation::SerializedRecord.new,
            transformations: [
              Transformation::EventClassRemapper.new(events_class_remapping),
              Transformation::SymbolizeMetadataKeys.new,
              Transformation::Serialization.new(serializer: serializer),
            ]
          ))
        end
      end
    end
  end
  ```
  
  When you define new custom mapper you could use mapper [PipelineMapper](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/pipeline_mapper.rb) as base class and provide your transformations pipeline.
  
  Each transformation must implement 2 methods: `dump(item)` & `load(item)`. Both methods take a `RubyEventStore::Mappers::Transformation::Item` and returns new instance of it, transformed. Transformation shall not modify given transformation item and shall return new instance as a result.
  
  If you use different classes to represent domain event & serialized record you shall also define edge transformations for your pipeline definition.
  
  Example of custom mapper build based on mappers pipeline:
  
  ```ruby
  require 'msgpack'
  
  class MessagePackSerialization
    def dump(item)
      RubyEventStore::Mappers::Transformation::Item.new(
        event_id:   item.event_id,
        metadata:   item.metadata.to_msg_pack,
        data:       item.data.to_msg_pack,
        event_type: item.event_type
      )
    end
  
    def load(item)
      RubyEventStore::Mappers::Transformation::Item.new(
        event_id:   item.event_id,
        metadata:   MessagePack.unpack(item.metadata),
        data:       MessagePack.unpack(item.data),
        event_type: item.event_type
      )
    end
  end
  
  class MyHashToMessagePackMapper < RubyEventStore::Mappers::PipelineMapper
    def initialize
      super(RubyEventStore::Mappers::Pipeline.new(
        transformations: [
          MessagePackSerialization.new,
        ]
      ))
    end
  end
  ```
  
  You could build your own transformations or use existing ones combined with the ones build by you. We strongly encourage you to share your transformations as a part of [RES-contrib](https://github.com/RailsEventStore/rails_event_store/tree/master/contrib).
  
  Check out the code of our [mappers](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/) and [transformations](https://github.com/RailsEventStore/rails_event_store/blob/master/ruby_event_store/lib/ruby_event_store/mappers/transformation/) on github for examples on how to implement mappers & transformations.
  
  You can pass a different `mapper` as a dependency when [instantiating the client](/docs/install).
  
  