mirror of
https://github.com/apple/pkl.git
synced 2026-06-06 13:52:49 +02:00
SPICE-0024: Annotation converters (#1333)
This enables defining declarative key and/or value transformations in cases where neither `Class`- nor path-based converters can be applied gracefully. It is also the only way to express transforming the resulting property names in `Typed` objects without applying a converter to the entire containing type, which is cumbersome at best. SPICE: https://github.com/apple/pkl-evolution/pull/26
This commit is contained in:
@@ -32,6 +32,11 @@
|
||||
module pkl.pklbinary
|
||||
|
||||
/// Render values as `pkl-binary`.
|
||||
///
|
||||
/// The `pkl-binary` renderer disables all [ConvertProperty] annotation converters by default
|
||||
/// because `pkl-binary` data is intended to closely represent native Pkl types and data.
|
||||
/// This behavior may be overridden for [ConvertProperty] or its subclasses by adding an entry to
|
||||
/// [Renderer.convertPropertyTransformers].
|
||||
class Renderer extends BytesRenderer {
|
||||
/// Renders [value] as `pkl-binary`.
|
||||
external function renderValue(value: Any): Bytes
|
||||
@@ -40,4 +45,11 @@ class Renderer extends BytesRenderer {
|
||||
///
|
||||
/// Every `pkl-binary` value is also a valid document.
|
||||
external function renderDocument(value: Any): Bytes
|
||||
|
||||
convertPropertyTransformers {
|
||||
// disable all property conversions by default
|
||||
[ConvertProperty] {
|
||||
render = (property, _) -> property
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user