This has been banging around in my head for a while and I finally needed to get it out.
This PR adds a new property BaseValueRenderer#annotationConverters that enables defining converters that act on both the property name and value of annotated properties of Typed values.
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.
This PR originally overloaded BaseValueRenderer#converters for this purpose. This implementation has been preserved in the first commit in the PR if you wish to compare that to implementation with the new property. A limitation of the previous design is that you can't have both a class and annotation converter for the same Annotation subclass (though this is probably unlikely to be an issue in practice).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/apple/pkl/pull/1333
**Author:** [@HT154](https://github.com/HT154)
**Created:** 11/26/2025
**Status:** 🔄 Open
**Base:** `main` ← **Head:** `annotation-converters`
---
### 📝 Commits (3)
- [`08871a2`](https://github.com/apple/pkl/commit/08871a26a3ef1b16a3454fbafe626fcd69f68c31) Add `Annotation`-based converters
- [`274ba33`](https://github.com/apple/pkl/commit/274ba33f07a817148620086b27e0101972439c48) Annotation converters as a separate BaseRenderer property
- [`192ed70`](https://github.com/apple/pkl/commit/192ed70f8534ee48c360fae196a8ab2265d413f7) Add implicit property name converter annotations for built-in renderers
### 📊 Changes
**46 files changed** (+639 additions, -71 deletions)
<details>
<summary>View changed files</summary>
📝 `pkl-core/src/main/java/org/pkl/core/ast/member/ClassProperty.java` (+16 -7)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/Identifier.java` (+1 -0)
➕ `pkl-core/src/main/java/org/pkl/core/runtime/JsonModule.java` (+45 -0)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/JsonnetModule.java` (+9 -1)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/ModuleCache.java` (+8 -2)
➕ `pkl-core/src/main/java/org/pkl/core/runtime/ProtobufModule.java` (+45 -0)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/TestRunner.java` (+2 -2)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmClass.java` (+2 -2)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmFunction.java` (+6 -0)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmPklBinaryEncoder.java` (+1 -1)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmValueConverter.java` (+5 -0)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/XmlModule.java` (+9 -1)
➕ `pkl-core/src/main/java/org/pkl/core/runtime/YamlModule.java` (+45 -0)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/AbstractRenderer.java` (+18 -3)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/PklConverter.java` (+85 -2)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/base/JsonRendererNodes.java` (+5 -3)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/base/PListRendererNodes.java` (+1 -3)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/base/PcfRendererNodes.java` (+6 -4)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/base/PropertiesRendererNodes.java` (+2 -3)
📝 `pkl-core/src/main/java/org/pkl/core/stdlib/base/YamlRendererNodes.java` (+7 -3)
_...and 26 more files_
</details>
### 📄 Description
This has been banging around in my head for a while and I finally needed to get it out.
This PR adds a new property `BaseValueRenderer#annotationConverters` that enables defining converters that act on both the property name and value of annotated properties of `Typed` values.
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.
This PR originally overloaded `BaseValueRenderer#converters` for this purpose. This implementation has been preserved in the first commit in the PR if you wish to compare that to implementation with the new property. A limitation of the previous design is that you can't have both a class and annotation converter for the same `Annotation` subclass (though this is probably unlikely to be an issue in practice).
SPICE: https://github.com/apple/pkl-evolution/pull/26
This also fixes a silly wart in the API for getting class property mirrors.
Resolves #576
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/1333
Author: @HT154
Created: 11/26/2025
Status: 🔄 Open
Base:
main← Head:annotation-converters📝 Commits (3)
08871a2AddAnnotation-based converters274ba33Annotation converters as a separate BaseRenderer property192ed70Add implicit property name converter annotations for built-in renderers📊 Changes
46 files changed (+639 additions, -71 deletions)
View changed files
📝
pkl-core/src/main/java/org/pkl/core/ast/member/ClassProperty.java(+16 -7)📝
pkl-core/src/main/java/org/pkl/core/runtime/Identifier.java(+1 -0)➕
pkl-core/src/main/java/org/pkl/core/runtime/JsonModule.java(+45 -0)📝
pkl-core/src/main/java/org/pkl/core/runtime/JsonnetModule.java(+9 -1)📝
pkl-core/src/main/java/org/pkl/core/runtime/ModuleCache.java(+8 -2)➕
pkl-core/src/main/java/org/pkl/core/runtime/ProtobufModule.java(+45 -0)📝
pkl-core/src/main/java/org/pkl/core/runtime/TestRunner.java(+2 -2)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmClass.java(+2 -2)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmFunction.java(+6 -0)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmPklBinaryEncoder.java(+1 -1)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmValueConverter.java(+5 -0)📝
pkl-core/src/main/java/org/pkl/core/runtime/XmlModule.java(+9 -1)➕
pkl-core/src/main/java/org/pkl/core/runtime/YamlModule.java(+45 -0)📝
pkl-core/src/main/java/org/pkl/core/stdlib/AbstractRenderer.java(+18 -3)📝
pkl-core/src/main/java/org/pkl/core/stdlib/PklConverter.java(+85 -2)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/JsonRendererNodes.java(+5 -3)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/PListRendererNodes.java(+1 -3)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/PcfRendererNodes.java(+6 -4)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/PropertiesRendererNodes.java(+2 -3)📝
pkl-core/src/main/java/org/pkl/core/stdlib/base/YamlRendererNodes.java(+7 -3)...and 26 more files
📄 Description
This has been banging around in my head for a while and I finally needed to get it out.
This PR adds a new property
BaseValueRenderer#annotationConvertersthat enables defining converters that act on both the property name and value of annotated properties ofTypedvalues.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 inTypedobjects without applying a converter to the entire containing type, which is cumbersome at best.This PR originally overloaded
BaseValueRenderer#convertersfor this purpose. This implementation has been preserved in the first commit in the PR if you wish to compare that to implementation with the new property. A limitation of the previous design is that you can't have both a class and annotation converter for the sameAnnotationsubclass (though this is probably unlikely to be an issue in practice).SPICE: https://github.com/apple/pkl-evolution/pull/26
This also fixes a silly wart in the API for getting class property mirrors.
Resolves #576
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.