RegistryBuilder

io.github.mbannour.mongo.codecs.RegistryBuilder$package.RegistryBuilder

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def apply(base: CodecRegistry, config: CodecConfig): RegistryBuilder

Create builder from base registry with custom configuration

Create builder from base registry with custom configuration

Attributes

def from(base: CodecRegistry): RegistryBuilder

Create builder from base registry with default configuration

Create builder from base registry with default configuration

Attributes

Extensions

Extensions

extension (builder: RegistryBuilder)
def build: CodecRegistry

Build the final CodecRegistry.

Build the final CodecRegistry.

This is when the actual registry is constructed from all registered codecs and providers. Call this method only once at the end of your configuration chain.

Attributes

Configure with a function - functional approach for flexible configuration.

Configure with a function - functional approach for flexible configuration.

This is the most flexible configuration method, allowing you to transform the configuration using any logic you need.

Value parameters

f

Function to transform the current configuration

Attributes

Example
 // Simple configuration
 builder.configure(_.copy(noneHandling = NoneHandling.Ignore))
 // Using helper methods on CodecConfig
 builder.configure(_.withIgnoreNone.withDiscriminator("_type"))
 // Conditional configuration
 builder.configure { config =>
   if (useEncoding) config.withEncodeNone else config.withIgnoreNone
 }
def discriminator(field: String): RegistryBuilder

Set the discriminator field name for sealed hierarchies.

Set the discriminator field name for sealed hierarchies.

Value parameters

field

The field name to use for type discriminators (default: "_t")

Attributes

Switch policy: encode None as BSON null.

Switch policy: encode None as BSON null.

Attributes

Switch policy: omit None fields entirely from BSON documents.

Switch policy: omit None fields entirely from BSON documents.

Attributes

inline def register[T : ClassTag]: RegistryBuilder

Register a type with automatic codec derivation.

Register a type with automatic codec derivation.

Relies on Scala 3 inline macros to auto-generate the BSON codec. Works for nested case classes and sealed hierarchies.

Performance note: Intermediate registries are cached to avoid rebuilding the same registry multiple times during chained register calls.

Type parameters

T

The type to register (must be a case class)

Attributes

inline def registerAll[T <: Tuple]: RegistryBuilder

Batch register multiple types using tuple syntax.

Batch register multiple types using tuple syntax.

This is more efficient than calling register multiple times separately as it minimizes intermediate registry builds.

Type parameters

T

A tuple of types to register

Attributes

Example
 builder.registerAll[(Person, Address, Department)]
def withCodec[A](codec: Codec[A]): RegistryBuilder

Add a single explicit codec.

Add a single explicit codec.

Useful for value classes or third-party types where automatic derivation is not possible.

Value parameters

codec

The codec to add

Attributes

def withCodecs(codecs: Codec[_]*): RegistryBuilder

Add multiple codecs at once.

Add multiple codecs at once.

Value parameters

codecs

Variable number of codecs to add

Attributes

Set the codec configuration directly.

Set the codec configuration directly.

Value parameters

newConfig

The codec configuration to use

Attributes

extension (registry: CodecRegistry)

Create a new builder with custom configuration

Create a new builder with custom configuration

Attributes

Create a new builder from this registry

Create a new builder from this registry

Attributes