Skip to content

Commit 2df738b

Browse files
committed
Update readme with decodeMultiple
add documentation about decodeMultiple functionality
1 parent c77fe9a commit 2df738b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

readme.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ The transformer interface defines two methods:
5353
* transforms: gives you the full qualified class name e.g.: Your\Namespace\Class
5454
```php
5555
class PersonTransformer implements Transformer {
56-
56+
5757
public function register(ClassBindings $classBindings)
5858
{
5959
$classBindings->register(new FieldBinding('address', 'address', Address::class);
6060
}
61-
61+
6262
public function transforms()
6363
{
6464
return Person::class;
@@ -81,6 +81,17 @@ The `JsonDecoder` class accepts two boolean constructor parameters to enable the
8181

8282
To do so a so called `PropertyAccessor` will be installed and on property set the proxy will set the property to accessible, set the according value and then will set the property to not accessible again.
8383

84+
### Transforming an array of elements
85+
If your json contains an array of elements at the root level you can use the `decodeMultiple` method to transform the json data into an array of class type objects.
86+
87+
```php
88+
$jsonDecoder = new JsonDecoder();
89+
90+
$jsonData = '[{"id": 1, "name": "John Doe"}, {"id": 2, "name": "Jane Doe"}]';
91+
92+
$personArray = $jsonDecoder->decodeMultiple($jsonData, Person::class);
93+
```
94+
8495
## Documentation
8596

8697
### Transformer Bindings

0 commit comments

Comments
 (0)