NameMapper

zio.blocks.schema.NameMapper
See theNameMapper companion trait
object NameMapper

The NameMapper object provides a set of predefined strategies for transforming string names into common naming conventions, such as snake_case, camelCase, PascalCase, and kebab-case. Additionally, it allows for custom transformations via the Custom case class.

This object defines several NameMapper implementations:

  • SnakeCase: Transforms strings to snake_case (e.g., "exampleName" → "example_name").
  • CamelCase: Transforms strings to camelCase (e.g., "example_name" → "exampleName").
  • PascalCase: Transforms strings to PascalCase (e.g., "example_name" → "ExampleName").
  • KebabCase: Transforms strings to kebab-case (e.g., "exampleName" → "example-name").
  • Identity: Returns the input string as-is, performing no transformation.
  • Custom: Allows for user-defined transformations by applying a given function to the input string.

Attributes

Companion
trait
Source
NameMapper.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
NameMapper.type

Members list

Type members

Classlikes

case object CamelCase extends NameMapper

A NameMapper implementation that transforms a string into camelCase format.

A NameMapper implementation that transforms a string into camelCase format.

This object overrides the apply method to enforce the camelCase convention on the input string, while leaving the rest of the characters unmodified, except for case adjustments as required by the camelCase format.

The transformation is applied using an internal implementation that ensures the following:

  • Underscores (_) and dashes (-) are treated as delimiters and are removed.
  • The character immediately following a delimiter is converted to uppercase.
  • The first character is always converted to lowercase unless the input string already conforms to camelCase.

Attributes

Source
NameMapper.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
Self type
CamelCase.type
case class Custom(f: String => String) extends NameMapper

A case class that provides a custom implementation of the NameMapper trait.

A case class that provides a custom implementation of the NameMapper trait.

The Custom class allows for the transformation of strings (typically member names) using a user-defined function. This transformation logic is encapsulated in the function f provided at instantiation.

Value parameters

f

A function that defines how to transform a string. The function takes a string (e.g., a member name) as input and returns the transformed string as output.

Attributes

Source
NameMapper.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
case object Identity extends NameMapper

An implementation of the NameMapper trait that performs no transformation on the provided member name. The identity operation is applied, where the input string is returned unchanged.

An implementation of the NameMapper trait that performs no transformation on the provided member name. The identity operation is applied, where the input string is returned unchanged.

It is a default implementation of the NameMapper trait, which can be used in the JSON codec derivation.

Also, this is useful in cases where there is a need to override field or case names during custom codec derivation to be different from the top-level one (e.g., when using a custom codec for a nested case class).

Attributes

Source
NameMapper.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
Self type
Identity.type
case object KebabCase extends NameMapper

A NameMapper implementation that converts member names to kebab-case.

A NameMapper implementation that converts member names to kebab-case.

By overriding the apply method, this object enforces a kebab-case naming convention for input strings. It uses a helper function to normalize the member name, replacing uppercase letters or existing separators with lowercase letters and a hyphen (-) as the separator.

Attributes

Source
NameMapper.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
Self type
KebabCase.type
case object PascalCase extends NameMapper

A NameMapper implementation that converts string names to PascalCase. PascalCase is a naming convention where each word starts with an uppercase letter and is concatenated without any separators.

A NameMapper implementation that converts string names to PascalCase. PascalCase is a naming convention where each word starts with an uppercase letter and is concatenated without any separators.

Attributes

Source
NameMapper.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
Self type
PascalCase.type
case object SnakeCase extends NameMapper

A predefined implementation of the NameMapper trait that converts a given string into snake_case format by replacing transitions between uppercase and lowercase letters with underscores (_) and converting all characters to lowercase.

A predefined implementation of the NameMapper trait that converts a given string into snake_case format by replacing transitions between uppercase and lowercase letters with underscores (_) and converting all characters to lowercase.

For example, "memberName" would be transformed into "member_name".

Attributes

Source
NameMapper.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait NameMapper
trait String => String
class Object
trait Matchable
class Any
Show all
Self type
SnakeCase.type

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def fromString(s: String): NameMapper

Parses a built-in naming strategy string into a NameMapper.

Parses a built-in naming strategy string into a NameMapper.

Accepted values are identity, snake_case, camelCase, kebab-case, and PascalCase.

Attributes

Throws
java.lang.IllegalArgumentException

if the provided strategy name does not match one of the supported built-in strategies.

Source
NameMapper.scala