-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom serialization for specific classes
- Loading branch information
Tino Adams
committed
Jun 9, 2016
1 parent
68c6a72
commit 5c25ea2
Showing
5 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Zumba\JsonSerializer\Test\SupportClasses; | ||
|
||
class MyType | ||
{ | ||
public $field1; | ||
public $field2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Zumba\JsonSerializer\Test\SupportClasses; | ||
|
||
class MyTypeSerializer | ||
{ | ||
public function serialize(MyType $obj) | ||
{ | ||
return array('fields' => $obj->field1 . ' ' . $obj->field2); | ||
} | ||
|
||
public function unserialize($values) | ||
{ | ||
list($field1, $field2) = explode(' ', $values['fields']); | ||
$obj = new MyType(); | ||
$obj->field1 = $field1; | ||
$obj->field2 = $field2; | ||
return $obj; | ||
} | ||
} |