Skip to content

Commit

Permalink
Record need JsonSerialize #390
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Nov 19, 2016
1 parent ca96ff7 commit 6bdcfad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/DataMapper/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Entity is a Data object sub class, we can set fields of this object
* then help us filter non necessary values to prevent error when inserting to database.
*/
class Entity extends Data
class Entity extends Data implements \JsonSerializable
{
const DUMP_ALL_DATA = true;

Expand Down Expand Up @@ -499,4 +499,17 @@ protected function toCamelCase($input)

return str_ireplace(' ', '', $input);
}

/**
* Specify data which should be serialized to JSON
*
* @return mixed data which can be serialized by json_encode(),
* which is a value of any type other than a resource.
*
* @since 3.1.3
*/
public function jsonSerialize()
{
return $this->data;
}
}
10 changes: 10 additions & 0 deletions src/DataMapper/Test/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,14 @@ public function testMutator()

$this->assertEquals('yoo_bar', $entity->flower_sakura);
}

/**
* testJsonSerialize
*
* @return void
*/
public function testJsonSerialize()
{
$this->assertEquals(json_encode($this->instance->dump(true)), json_encode($this->instance));
}
}

0 comments on commit 6bdcfad

Please sign in to comment.