Skip to content

Commit

Permalink
Merge branch 'bankiru-bugfix/null-in-valued-arrays'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonatan Männchen committed May 3, 2016
2 parents 7a3a187 + 9a1ede8 commit 8a47087
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/GenericSerializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function visitArray($data, array $type, Context $context)
foreach ($data as $k => $v) {
$v = $this->navigator->accept($v, $this->getElementType($type), $context);

if (null === $v && ( ! is_string($k) || ! $context->shouldSerializeNull())) {
if (null === $v && is_string($k) && !$context->shouldSerializeNull()) {
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Serializer/JsonSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use JMS\Serializer\EventDispatcher\Event;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\VisitorInterface;
use JMS\Serializer\Tests\Fixtures\Author;
use JMS\Serializer\Tests\Fixtures\AuthorList;
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function getContent($key)
$outputs['virtual_properties_low'] = '{"low":1}';
$outputs['virtual_properties_high'] = '{"high":8}';
$outputs['virtual_properties_all'] = '{"low":1,"high":8}';
$outputs['nullable'] = '{"foo":"bar","baz":null}';
$outputs['nullable'] = '{"foo":"bar","baz":null,"0":null}';
$outputs['null'] = 'null';
$outputs['simple_object_nullable'] = '{"foo":"foo","moo":"bar","camel_case":"boo","null_property":null}';
$outputs['input'] = '{"attributes":{"type":"text","name":"firstname","value":"Adrien"}}';
Expand All @@ -94,7 +95,7 @@ protected function getContent($key)
$outputs['car'] = '{"km":5,"type":"car"}';
$outputs['car_without_type'] = '{"km":5}';
$outputs['garage'] = '{"vehicles":[{"km":3,"type":"car"},{"km":1,"type":"moped"}]}';
$outputs['tree'] = '{"tree":{"children":[{"children":[{"children":[],"foo":"bar"}],"foo":"bar"}],"foo":"bar"}}';
$outputs['tree'] = '{"tree":{"children":[{"children":[{"children":[null],"foo":"bar"}],"foo":"bar"}],"foo":"bar"}}';
$outputs['discriminator_groups_correct'] = '{"type":"car"}';
$outputs['discriminator_groups_incorrect'] = '{}';
$outputs['discriminator_groups_default'] = '{"km":42}';
Expand Down

0 comments on commit 8a47087

Please # to comment.