Skip to content

Commit 5fdbdfe

Browse files
committed
add enum stuff to readme
1 parent d2a457f commit 5fdbdfe

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ A PHP library for (de-)serialization using attributes and reflection.
99
- [Required](#required)
1010
- [Allow Null](#allow-null)
1111
- [Item Type](#item-type)
12+
- [Serializer and Deserializer](#serializer-and-deserializer)
13+
- [Item Serializer and Item Deserializer](#item-serializer-and-item-deserializer)
1214
- [Exceptions](#exceptions)
1315
- [SerializationException](#serializationexception)
1416
- [InvalidInputException](#invalidinputexception)
1517
- [MissingPropertyException](#missingpropertyexception)
1618
- [IncorrectTypeException](#incorrecttypeexception)
1719
- [UnsupportedTypeException](#unsupportedtypeexception)
20+
- [InvalidEnumBackingException](#invalidenumbackingexception)
1821
- [Custom Serializers](#custom-serializers)
1922

2023
### Installation
@@ -70,6 +73,9 @@ $example = ExampleClass::tryFromJson('{ "name": "John", "age": 25, "last_name":
7073
> [!NOTE]
7174
> Deserialization is not supported for intersection types as there is no way to determine the correct type.
7275
76+
> [!NOTE]
77+
> Serialization and deserialization of enums is only supported for backed enums.
78+
7379
If you prefer you can also serialize and deserialize manually.
7480

7581
```php
@@ -206,6 +212,7 @@ Both of these exceptions extend [InvalidInputException](#invalidinputexception).
206212

207213
During deserialization, the following additional exceptions may be thrown:
208214
- [UnsupportedTypeException](#unsupportedtypeexception)
215+
- [InvalidEnumBackingException](#invalidenumbackingexception)
209216
- [JsonException](https://www.php.net/manual/en/class.jsonexception.php)
210217

211218
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.
234241
If an intersection type is encountered during deserialization, this exception is thrown.
235242
It's also thrown if a php built-in type is encountered that is not yet supported by the library.
236243

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+
237249
### Custom Serializers
238250
If you want to write a serializer for a different format, you can use the ArraySerializer and ArrayDeserializer class.
239251
These convert the object to an associative array and vice versa.

0 commit comments

Comments
 (0)