DownloadJSON Object Mapper Documentation
Examples
-
Simple Mapping
-
Mapping with Typehints
-
Mapping Alternative Property Names
-
Using Transformers
-
Convert an Mapped Object to JSON
-
Multiple Annotations
Basic usage
JOM is totally easy to use.
Simply put the annotation @MintWare\JOM\JsonField() to your class properties.
Example
Dataset: {
"first_name": "Pete",
"surname": "Peterson",
"age": 28,
"address": {
"street": "Mainstreet 22a",
"zip_code": "A-12345",
"town": "Best Town"
}
}
Data Class: <?php
use MintWare\JOM\JsonField;
class Person
{
/ @JsonField(name="first_name", type="string") */
public $firstName;
/ @JsonField(name="surname", type="string") */
public $lastname;
/ @JsonField() */
public $age;
/ @JsonField(type="Some\Other\DataClass\Address") */
public $address;
}
Map the JSON: <?php
use MintWare\JOM\ObjectMapper;
$mapper = new ObjectMapper();
$person = $mapper->mapJson(file_get_contents('person.json'), Person::class);
|