Skip to content
This repository

Configuring Formats

RABL supports configuring multiple formats as shown below:

Message Pack

Rabl also includes optional support for Message Pack serialization format using the msgpack gem. To enable, include the msgpack gem in your project's Gemfile. Then use Rabl as normal with the msgpack format (akin to json and xml formats).

# Gemfile
gem 'msgpack', '~> 0.4.5'

One can additionally use a custom Message Pack implementation by setting the Rabl msgpack_engine configuration attribute. This custom message pack engine must conform to the MessagePack#pack method signature.

class CustomEncodeEngine
  def self.pack string
    # Custom Encoding by your own engine.
  end
end

Rabl.configure do |config|
  config.msgpack_engine = CustomEncodeEngine
end

NOTE: Attempting to render the msgpack format without either including the msgpack gem or setting a msgpack_engine will cause an exception to be raised.

BSON

Rabl also includes optional support for BSON serialization format using the bson gem. To enable, include the bson gem in your project's Gemfile. Then use Rabl as normal with the bson format (akin to json and xml formats).

# Gemfile
gem 'bson', '~> 1.5.2'

To use it with Rails, also register the bson mime type format:

# config/initializers/mime_types.rb
Mime::Type.register "application/bson", :bson

One can additionally use a custom BSON implementation by setting the Rabl bson_engine configuration attribute. This custom BSON engine must conform to the BSON#serialize method signature.

class CustomEncodeEngine
  def self.serialize string
    # Custom Encoding by your own engine.
  end
end

Rabl.configure do |config|
  config.bson_engine = CustomEncodeEngine
end

NOTE: Attempting to render the bson format without either including the bson gem or setting a bson_engine will cause an exception to be raised.

Plist

Rabl also includes optional support for Plist serialization format using the plist gem. To enable, include the plist gem in your project's Gemfile. Then use Rabl as normal with the plist format (akin to other formats).

# Gemfile
gem 'plist'

There is also an option for a custom Plist implementation by setting the Rabl plist_engine configuration attribute.

class CustomEncodeEngine
  def self.dump string
    # Custom Encoding by your own engine.
  end
end

Rabl.configure do |config|
  config.plist_engine = CustomEncodeEngine
end

NOTE: Attempting to render the plist format without either including the plist gem or setting a plist_engine will cause an exception to be raised.

Something went wrong with that request. Please try again.