Skip to content

Commit

Permalink
[JsonConverter] Fixed hydrate null value (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: roxblnfk <[email protected]>
  • Loading branch information
root-aza and roxblnfk authored Jan 15, 2024
1 parent 06639b2 commit 7fe594b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 1 addition & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<files psalm-version="5.19.0@06b71be009a6bd6d81b9811855d6629b9fe90e1b">
<file src="src/Activity.php">
<ImplicitToStringCast>
<code>$type</code>
Expand Down Expand Up @@ -938,9 +938,6 @@
<InvalidDocblock>
<code>interface RepositoryInterface extends \IteratorAggregate, \Countable</code>
</InvalidDocblock>
<InvalidTemplateParam>
<code>callable(TEntry): bool</code>
</InvalidTemplateParam>
<MissingTemplateParam>
<code>\IteratorAggregate</code>
</MissingTemplateParam>
Expand Down
4 changes: 4 additions & 0 deletions src/DataConverter/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function fromPayload(Payload $payload, Type $type)
throw new DataConverterException($e->getMessage(), $e->getCode(), $e);
}

if ($data === null && $type->allowsNull()){
return null;
}

switch ($type->getName()) {
case Type::TYPE_ANY:
return $data;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Repository/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
interface RepositoryInterface extends \IteratorAggregate, \Countable
{
/**
* @param callable(TEntry): bool $filter
* @param callable(Identifiable): bool $filter
* @return $this
*/
public function filter(callable $filter): self;
Expand Down
14 changes: 13 additions & 1 deletion tests/Unit/DataConverter/JsonConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Temporal\Tests\Unit\DataConverter;

use Ramsey\Uuid\Uuid;
use Temporal\DataConverter\EncodingKeys;
use Temporal\DataConverter\JsonConverter;
use Temporal\DataConverter\PayloadConverterInterface;
use Temporal\DataConverter\Type;
use Temporal\Tests\Unit\UnitTestCase;

/**
Expand Down Expand Up @@ -42,4 +42,16 @@ public function testUuidToPayload(): void
$payload->getData(),
);
}

public function testNullFromPayload(): void
{
$converter = $this->create();
$payload = $converter->toPayload(null);

$this->assertNotNull($payload);

$value = $converter->fromPayload($payload, new Type(Type::TYPE_STRING, allowsNull: true));

$this->assertNull($value);
}
}

0 comments on commit 7fe594b

Please sign in to comment.