We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This code https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/GenericSerializationVisitor.php#L104-L106
if (null === $v && ( ! is_string($k) || ! $context->shouldSerializeNull())) { continue; }
Test
$context = \JMS\Serializer\SerializationContext::create(); $context->setSerializeNull(true); var_dump($serializer->toArray([1, null, 2], $context)); $context = \JMS\Serializer\SerializationContext::create(); $context->setSerializeNull(true); var_dump($serializer->serialize([1, null, 2], 'json', $context));
Output
array(2) { [0] => int(1) [2] => int(2) } string(13) "{"0":1,"2":2}"
Dropping null value makes the json_encode think of the data like the named properties. I think correct condition should be
json_encode
if (null == $v && is_string($k) && !$context->shouldSerializeNull()) { continue; }
In this case we drop null only in case they are at hash array, not positional.
The text was updated successfully, but these errors were encountered:
b0a46c8
The given commit actually does not resolve the problem.
It fails a simple test
public function testNullArraySerialization() { $context = SerializationContext::create(); $context->setSerializeNull(true); $array = [0, null, 'a']; self::assertSame($array, $this->serializer->toArray($array, $context)); }
How we force an array being normalized as array, not object?
Sorry, something went wrong.
No branches or pull requests
This code
https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/GenericSerializationVisitor.php#L104-L106
Test
Output
Dropping null value makes the
json_encode
think of the data like the named properties. I think correct condition should beif (null == $v && is_string($k) && !$context->shouldSerializeNull()) {
continue;
}
In this case we drop null only in case they are at hash array, not positional.
The text was updated successfully, but these errors were encountered: