CreateDerivedEnumerationPickler

sttp.tapir.json.pickler.CreateDerivedEnumerationPickler
class CreateDerivedEnumerationPickler[T](validator: Enumeration[T], schemaAnnotations: SchemaAnnotations[T])(implicit evidence$1: ClassTag[T])

A builder allowing deriving Pickler for enums, used by Pickler.derivedEnumeration. Can be used to set non-standard encoding logic, schema type or default value for an enum.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

inline def apply(encode: T => Any, schemaType: SchemaType[T], default: Option[T])(using m: SumOf[T]): Pickler[T]

Value parameters

encode

Specify how values of this type can be encoded to a raw value (typically a String; the raw form should correspond with schemaType). This encoding will be used when writing/reading JSON and generating documentation. Defaults to an identity function, which effectively means that .toString will be used to represent the enumeration in the docs.

schemaType

The low-level representation of the enumeration. Defaults to a string.

Attributes

inline def customStringBased(encode: T => String)(using SumOf[T]): Pickler[T]

Creates the Pickler assuming the low-level representation is a String. Provide your custom encoding function for representing an enum value as a String. It will be used to represent the enumeration in JSON and documentation. This approach is recommended if you need to encode enums using a common field in their base trait, or another specific logic for extracting string representation.

Creates the Pickler assuming the low-level representation is a String. Provide your custom encoding function for representing an enum value as a String. It will be used to represent the enumeration in JSON and documentation. This approach is recommended if you need to encode enums using a common field in their base trait, or another specific logic for extracting string representation.

Attributes

inline def defaultStringBased(using SumOf[T]): Pickler[T]

Creates the Pickler assuming the low-level representation is a String. The encoding function passes the object unchanged (which means .toString will be used to represent the enumeration in JSON and documentation). Typically you don't need to explicitly use Pickler.derivedEnumeration[T].defaultStringBased, as this is the default behavior of Pickler.derived for enums.

Creates the Pickler assuming the low-level representation is a String. The encoding function passes the object unchanged (which means .toString will be used to represent the enumeration in JSON and documentation). Typically you don't need to explicitly use Pickler.derivedEnumeration[T].defaultStringBased, as this is the default behavior of Pickler.derived for enums.

Attributes