Skip to content

Commit

Permalink
Work on feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasKenneth committed Mar 14, 2022
1 parent 72f43f4 commit a95f252
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions abstractions/php/src/Serialization/ParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Microsoft\Kiota\Abstractions\Types\Byte;
use Microsoft\Kiota\Abstractions\Types\Date;
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;

interface ParseNode {
/**
Expand Down Expand Up @@ -98,6 +99,11 @@ public function getEnumValue(string $targetEnum): ?Enum;
*/
public function getByteValue(): ?Byte;

/**
* Get a Stream from node.
* @return StreamInterface|null
*/
public function getBinaryContent(): ?StreamInterface;
/**
* Gets the callback called before the node is deserialized.
* @return callable the callback called before the node is deserialized.
Expand Down
17 changes: 12 additions & 5 deletions serialization/php/json/src/JsonParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,26 @@ private function assignFieldValues($result): void {
if (is_a($result, Parsable::class)){
$fieldDeserializers = $result->getFieldDeserializers();
}

$isAdditionalDataHolder = false;
$additionalData = [];
if (is_a($result, AdditionalDataHolder::class)) {
$isAdditionalDataHolder = true;
$additionalData = $result->getAdditionalData();
}
foreach ($this->jsonNode as $key => $value){
$deserializer = $fieldDeserializers[$key] ?? null;

if ($deserializer !== null){
$deserializer($result, new JsonParseNode($value));
} else if (is_a($result, AdditionalDataHolder::class)) {
$data = $result->getAdditionalData();
} else {
$key = (string)$key;
$data[$key] = $value;
$result->setAdditionalData($data);
$additionalData[$key] = $value;
}
}

if ( $isAdditionalDataHolder ) {
$result->setAdditionalData($additionalData);
}
}

/**
Expand Down

0 comments on commit a95f252

Please sign in to comment.