mirror of
https://github.com/apple/pkl.git
synced 2026-03-21 00:29:07 +01: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:
@@ -18,6 +18,16 @@
|
||||
@ModuleInfo { minPklVersion = "0.31.0" }
|
||||
module pkl.json
|
||||
|
||||
/// Annotate properties of classes and modules with this class to override how a [JsonRenderer]
|
||||
/// interprets a property's name.
|
||||
@Since { version = "0.31.0" }
|
||||
class Property extends ConvertProperty {
|
||||
/// The new name to use for the annotated property when rendered by [JsonRenderer].
|
||||
name: String
|
||||
|
||||
render = (prop, renderer) -> if (renderer is JsonRenderer) Pair(name, prop.value) else prop
|
||||
}
|
||||
|
||||
/// A JSON parser.
|
||||
///
|
||||
/// JSON values are mapped to Pkl values as follows:
|
||||
|
||||
Reference in New Issue
Block a user