square / pjson

JSON <=> PHP8+ objects serialization / deserialization library
Apache License 2.0
110 stars 7 forks source link

Added support for an array containing a backed enum type #28

Closed refring closed 1 year ago

refring commented 1 year ago

Hi, this change allows lists of backed enums without having to implement fromJsonData() on the enum.

Given the following enum:

enum Status : string
{
    case ON = 'ON';
    case OFF = 'OFF';
}

And the following property:

 #[Json('status_list', type: Status::class)]
 public array $statusList;

A json document like the following would return 3 Status enums:

{"status_list": ["ON", "OFF", "ON"]}
CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

khepin commented 1 year ago

Thank you, this looks pretty good. Would like to update one or 2 things before this makes it in.

refring commented 1 year ago

Thanks for the feedback, I've made the changes you suggested.