@@ -9,12 +9,15 @@ A PHP library for (de-)serialization using attributes and reflection.
9
9
- [ Required] ( #required )
10
10
- [ Allow Null] ( #allow-null )
11
11
- [ Item Type] ( #item-type )
12
+ - [ Serializer and Deserializer] ( #serializer-and-deserializer )
13
+ - [ Item Serializer and Item Deserializer] ( #item-serializer-and-item-deserializer )
12
14
- [ Exceptions] ( #exceptions )
13
15
- [ SerializationException] ( #serializationexception )
14
16
- [ InvalidInputException] ( #invalidinputexception )
15
17
- [ MissingPropertyException] ( #missingpropertyexception )
16
18
- [ IncorrectTypeException] ( #incorrecttypeexception )
17
19
- [ UnsupportedTypeException] ( #unsupportedtypeexception )
20
+ - [ InvalidEnumBackingException] ( #invalidenumbackingexception )
18
21
- [ Custom Serializers] ( #custom-serializers )
19
22
20
23
### Installation
@@ -70,6 +73,9 @@ $example = ExampleClass::tryFromJson('{ "name": "John", "age": 25, "last_name":
70
73
> [ !NOTE]
71
74
> Deserialization is not supported for intersection types as there is no way to determine the correct type.
72
75
76
+ > [ !NOTE]
77
+ > Serialization and deserialization of enums is only supported for backed enums.
78
+
73
79
If you prefer you can also serialize and deserialize manually.
74
80
75
81
``` php
@@ -206,6 +212,7 @@ Both of these exceptions extend [InvalidInputException](#invalidinputexception).
206
212
207
213
During deserialization, the following additional exceptions may be thrown:
208
214
- [ UnsupportedTypeException] ( #unsupportedtypeexception )
215
+ - [ InvalidEnumBackingException] ( #invalidenumbackingexception )
209
216
- [ JsonException] ( https://www.php.net/manual/en/class.jsonexception.php )
210
217
211
218
JsonException is a built-in PHP exception that is thrown when an error occurs during JSON encoding or decoding.
@@ -234,6 +241,11 @@ As noted above, deserializing intersection types is not supported.
234
241
If an intersection type is encountered during deserialization, this exception is thrown.
235
242
It's also thrown if a php built-in type is encountered that is not yet supported by the library.
236
243
244
+ #### InvalidEnumBackingException
245
+ This exception is thrown if an enum is deserialized with an invalid backing value.
246
+ This can happen if the value that is deserialized is not scalar,
247
+ or if the target enum does not have a matching case.
248
+
237
249
### Custom Serializers
238
250
If you want to write a serializer for a different format, you can use the ArraySerializer and ArrayDeserializer class.
239
251
These convert the object to an associative array and vice versa.
0 commit comments