Skip to content

Commit

Permalink
Attempt to normalize only if properties are available
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed Jan 10, 2025
1 parent e08cbfb commit 870c259
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Serializer/ElifeAssessmentNormalizer.php
Original file line number Diff line number Diff line change
@@ -44,11 +44,14 @@ public function supportsDenormalization($data, $type, $format = null) : bool
*/
public function normalize($object, $format = null, array $context = []) : array
{
$data = [
'title' => $object->getTitle(),
'significance' => $object->getSignificance(),
'strength' => $object->getStrength(),
];
$data = [];
$data['title'] = $object->getTitle();
if ($object->getSignificance() !== null) {
$data['significance'] = $object->getSignificance();
}
if ($object->getStrength() !== null) {
$data['strength'] = $object->getStrength();
}

return $data;
}

0 comments on commit 870c259

Please sign in to comment.