GSOC2025: Json Library for D, weekly update #7
Gaofei Qiu
qiugaofei53391 at gmail.com
Mon Aug 4 23:51:28 UTC 2025
We added the policy parameter to all deserializeImpl methods.
This allows users to customize deserialization for any specific
type, while the remaining types can still use the module-level
deserializeImpl method via UFCS.
deserializeImpl is like:
```d
void deserializeImpl(P, T, JT)(ref P policy, ref JT tokenizer,
ref T item) if (type constrains) {....}
```
An example of customized policy is like:
```d
static struct DTStringPolicy {
void deserializeImpl(JT, T)(ref JT tokenizer, ref T item)
{
static if (is(T == DateTime))
{
// Deserialize DateTime from a string
auto jsonItem = tokenizer.nextSignificant
.jsonExpect(JSONToken.String, "Parsing
DateTime");
item =
DateTime.fromSimpleString(extractString!string(jsonItem,
tokenizer.chain));
}
else {
// default to module behavior
.deserializeImpl(this, tokenizer, item);
};
}
}
```
https://github.com/schveiguy/jsoniopipe/pull/51
https://github.com/schveiguy/jsoniopipe/pull/52
More information about the Digitalmars-d
mailing list