Use custom annotations to override type validation during JSON to Typed conversion
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
**Problem Statement**
We have a use case where we need to selectively bypass type validation for properties marked with custom annotations during JSON-to-Typed object conversion.
**Current Behavior**
When using [deepToTyped converter](https://pkl-lang.org/package-docs/pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped/current/deepToTyped/index.html) to transform JSON data into Pkl Typed objects, all properties undergo strict type validation. For example, if a property is defined as String, the converter will fail if the JSON contains a non-string value.
**Desired Behavior**
We want to define custom annotations (e.g., @Secret) that, when applied to a property, allow the converter to bypass type validation for that specific property.
**Use Case Example**
Pkl Schema Definition:
```
class DatabaseConfig {
host: String
port: Int
@Secret
password: String // Should accept any JSON value type, not just strings
}
```
Input JSON:
```
{
"host": "localhost",
"port": 5432,
"password": {
"$secret": {
"type": "",
"name": "db_password"
}
}
}
```
Please suggest the best approach to achieve this.
1. What would be the most idiomatic way to handle annotation-based type validation bypassing in Pkl?
2. Are there existing patterns or mechanisms in Pkl that we should leverage for this use case?
Contributor guide
Research direction
Start with the deepToTyped converter referenced in the issue and review how custom annotations and type validation are currently handled. Determine whether annotation-controlled validation bypassing is supported or requires a new design, then define the expected behavior for the @Secret example and verify it with a focused conversion test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, json
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100