Skip to content

Commit

Permalink
TASK: #4736 Json serialize Subgraph correctly
Browse files Browse the repository at this point in the history
Resolves: #4736

example output:

```
{"contentRepositoryId":"default","contentStreamId":"a6e86502-5867-4460-a855-4134489d6b1b","dimensionSpacePoint":{"language":"en_US"},"visibilityConstraints":"075ae3d2fc31640504f814f60e5ef713"}
```
  • Loading branch information
mhsdesign committed Nov 12, 2023
1 parent 1801fbb commit 3a7aa79
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,9 @@ public function countNodes(): int
}
}

/**
* @return array<string,mixed>
*/
public function jsonSerialize(): array
public function jsonSerialize(): ContentSubgraphIdentity
{
return [
'contentStreamId' => $this->contentStreamId,
'dimensionSpacePoint' => $this->dimensionSpacePoint
];
return $this->getIdentity();
}

/** ------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,8 @@ private function getDatabaseConnection(): DatabaseConnection
return $this->databaseClient->getConnection();
}

/**
* @return array<string,mixed>
*/
public function jsonSerialize(): array
public function jsonSerialize(): ContentSubgraphIdentity
{
return [
'contentStreamId' => $this->contentStreamId,
'dimensionSpacePoint' => $this->dimensionSpacePoint
];
return $this->getIdentity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @api
*/
final class ContentRepositoryId
final class ContentRepositoryId implements \JsonSerializable
{
private function __construct(
public readonly string $value
Expand Down Expand Up @@ -47,4 +47,9 @@ public function equals(self $other): bool
{
return $this->value === $other->value;
}

public function jsonSerialize(): mixed
{
return $this->value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static function isFilterEmpty(object $filter): bool
return array_filter(get_object_vars($filter), static fn ($value) => $value !== null) === [];
}

public function jsonSerialize(): mixed
public function jsonSerialize(): ContentSubgraphIdentity
{
return $this->wrappedContentSubgraph->jsonSerialize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @api
*/
final class ContentSubgraphIdentity
final class ContentSubgraphIdentity implements \JsonSerializable
{
private function __construct(
public readonly ContentRepositoryId $contentRepositoryId,
Expand Down Expand Up @@ -90,4 +90,17 @@ public function withVisibilityConstraints(VisibilityConstraints $visibilityConst
$visibilityConstraints
);
}

/**
* @return array<string,mixed>
*/
public function jsonSerialize(): array
{
return [
'contentRepositoryId' => $this->contentRepositoryId,
'contentStreamId' => $this->contentStreamId,
'dimensionSpacePoint' => $this->dimensionSpacePoint,
'visibilityConstraints' => $this->visibilityConstraints
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,6 @@ public function retrieveNodePath(NodeAggregateId $nodeAggregateId): AbsoluteNode
* @internal this method might change without further notice.
*/
public function countNodes(): int;

public function jsonSerialize(): ContentSubgraphIdentity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @api
*/
final class VisibilityConstraints
final class VisibilityConstraints implements \JsonSerializable
{
protected bool $disabledContentShown = false;

Expand Down Expand Up @@ -49,4 +49,9 @@ public static function frontend(): VisibilityConstraints
{
return new VisibilityConstraints(false);
}

public function jsonSerialize(): string
{
return $this->getHash();
}
}

0 comments on commit 3a7aa79

Please sign in to comment.