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)

Merge two builders, combining their providers and codecs.

Merge two builders, combining their providers and codecs.

Config and base from the left builder are used; only providers and codecs are merged.

Value parameters

other

The builder to merge with

Attributes

Returns

A new builder with combined providers and codecs

Example
 val common = baseBuilder.register[Address].register[Person]
 val full = common ++ specificBuilder
def build: CodecRegistry

Build the final org.bson.codecs.configuration.CodecRegistry.

Build the final org.bson.codecs.configuration.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

Clear the cached temporary registry.

Clear the cached temporary registry.

Mainly useful for testing or debugging. The cache will be rebuilt on next register call.

Attributes

Returns

A new builder with cache cleared

def codecCount: Int

Get the number of explicitly registered codecs.

Get the number of explicitly registered codecs.

Attributes

Returns

Count of codecs added via withCodec or withCodecs

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)
 // Conditional configuration
 builder.configure { config =>
   if (useEncoding) config.withEncodeNone else config.withIgnoreNone
 }

Get the current codec configuration.

Get the current codec configuration.

Useful for debugging or conditional logic based on current settings.

Attributes

Returns

The current CodecConfig

Switch policy: encode None as BSON null.

Switch policy: encode None as BSON null.

Attributes

inline def hasCodecFor[T : ClassTag]: Boolean

Check if a codec is available for a given type.

Check if a codec is available for a given type.

Type parameters

T

The type to check

Attributes

Returns

true if a codec can be obtained for this type

Switch policy: omit None fields entirely from BSON documents.

Switch policy: omit None fields entirely from BSON documents.

Attributes

def isCached: Boolean

Check if this builder has a cached registry.

Check if this builder has a cached registry.

Useful for understanding performance characteristics during chained operations.

Attributes

Returns

true if a registry is cached

def isEmpty: Boolean

Check if the registry is empty (no codecs or providers registered).

Check if the registry is empty (no codecs or providers registered).

Attributes

Returns

true if no codecs or providers have been added

inline def just[T : ClassTag]: CodecRegistry

Register a single type and immediately build the registry.

Register a single type and immediately build the registry.

Convenience method for the common pattern of registering one type.

Type parameters

T

The type to register

Attributes

Example
 given CodecRegistry = MongoClient.DEFAULT_CODEC_REGISTRY.newBuilder.just[User]
def providerCount: Int

Get the number of registered codec providers.

Get the number of registered codec providers.

Each call to register[T] adds one provider.

Attributes

Returns

Count of providers from register and registerAll calls

inline def register[T](using ct: ClassTag[T]): 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.

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 builds the temporary registry only once.

Type parameters

T

A tuple of types to register

Attributes

Example
 builder.registerAll[(Person, Address, Department)]
inline def registerIf[T : ClassTag](condition: Boolean): RegistryBuilder

Conditionally register a type based on a runtime condition.

Conditionally register a type based on a runtime condition.

Useful for environment-specific or feature-flag based codec registration.

Type parameters

T

The type to register

Value parameters

condition

Whether to register the type

Attributes

Example
 builder
   .registerIf[DebugInfo](isDevelopment)
   .registerIf[AdminFeature](hasAdminAccess)
def summary: String

Get a summary of the builder's current state.

Get a summary of the builder's current state.

Useful for logging and debugging.

Attributes

Returns

A human-readable summary string

def toRegistry: CodecRegistry

Alias for build. Constructs the final codec registry.

Alias for build. Constructs the final codec registry.

Attributes

Returns

The assembled CodecRegistry

def tryGetCodec[T : ClassTag]: Option[Codec[T]]

Attempt to get a codec for a given type from the current registry state.

Attempt to get a codec for a given type from the current registry state.

This builds a snapshot registry if needed and attempts to retrieve a codec. Does not cache the result.

Type parameters

T

The type to check

Attributes

Returns

Some(codec) if available, None otherwise

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

def withProvider(provider: CodecProvider): RegistryBuilder

Add a single codec provider.

Add a single codec provider.

Attributes

def withProviders(providers: CodecProvider*): RegistryBuilder

Add multiple codec providers at once.

Add multiple codec providers at once.

Value parameters

providers

Variable number of codec providers to add

Attributes

inline def withTypes[T <: Tuple]: CodecRegistry

Register multiple types and immediately build the registry.

Register multiple types and immediately build the registry.

Convenience method for batch registration followed by build.

Type parameters

T

A tuple of types to register

Attributes

Example
 val registry = baseRegistry.newBuilder.withTypes[(User, Order, Product)]
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