Open Kingdutch opened 4 months ago
Oh geez. I don't know that can be done in TypeMap directly without a BC break. With union types it might be possible, at an API level, but I'm not sure if it's going to cause other issues. This is something I'd have to investigate in more detail, and I'm not sure when I'll have the opportunity to do so. (Though sponsorship to help me find the time is welcome.)
Looks like I didn't follow Garfield's Law: One is a special case of many. :-/
TypeMap currently only supports a single property but I'd like to be able to use multiple (2) properties to decide a class to deserialize to (and map a class to 2 properties on serialization). I can't implement this as custom typemap because the interface also provides only a single property at a time.
Detailed description
This would be an enhancement to the library.
It would allow serializing structures such as the following to classes in a V1/V2 namespace:
Context
I'm trying to bring the Lexical Editor editor state into PHP for storage and inspection. I'd love to use Serde to serialize/deserialize this. The lexical state provides a "type" and "version" field for each node because newer editor versions may contain additional info (e.g. to be up to date with changes in the HTML spec).
There are similar JSON based formats that may have a type and version property. For example the CloudEvents Specification has a "specversion" and event "type" field.
Possible implementation
I'm not entirely sure. I think turning the
string
in TypeMap (in new attribute) intostring[]
and allowing those from custom typemaps (although an array lookup table could possibly be made within an attribute). This would require the place where the typemap is called to be updated to deal with N property lookups.