Skip to content

Commit

Permalink
Nullable array inconsistency
Browse files Browse the repository at this point in the history
Fixes #593

Introduced with 8cb1e3c containing a non exact test case
  • Loading branch information
goetas committed Oct 28, 2016
1 parent 2cef890 commit 8f09cee
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/JMS/Serializer/GenericSerializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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() !== true)) {
if (null === $v && ( ! is_scalar($k) || $context->shouldSerializeNull() !== true)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/JMS/Serializer/YamlSerializationVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function visitArray($data, array $type, Context $context)
|| array_keys($data) === range(0, count($data) - 1);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 Down
1 change: 1 addition & 0 deletions tests/JMS/Serializer/Tests/Serializer/yml/nullable.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
foo: bar
baz: null
0: null

0 comments on commit 8f09cee

Please sign in to comment.