Crell / Serde

Robust Serde (serialization/deserialization) library for PHP 8.
Other
299 stars 14 forks source link

Respect strict mode for sequences #34

Closed Crell closed 1 year ago

Crell commented 1 year ago

Description

The sequence deformatter was not respecting strict mode. Now, if strict mode is set, it will reject anything that is not a sequence. In weak mode, it will accept a non-sequence list but call array_values() on it to coerce it to a sequence.

That allows fields to opt-in to being more permissive about what they accept, but still guarantees that after deserialiation a #[SequenceField] field will have a proper list/sequence in it, period.

There may be more strictness checks we can include, based on the array and key type, but that's for another time.

Motivation and context

Resolves #29.

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply: