8000 [Serializer] Fixed throwing exception with option JSON_PARTIAL_OUTPUT… · symfony/symfony@15f098b · GitHub
[go: up one dir, main page]

Skip to content

Commit 15f098b

Browse files
diversantvlznicolas-grekas
authored andcommitted
[Serializer] Fixed throwing exception with option JSON_PARTIAL_OUTPUT_ON_ERROR
1 parent 05adcd0 commit 15f098b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Serializer/Encoder/JsonEncode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function encode($data, $format, array $context = array())
5555

5656
$encodedJson = json_encode($data, $context['json_encode_options']);
5757

58-
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
58+
$this->lastError = json_last_error();
59+
if (JSON_ERROR_NONE !== $this->lastError && false === $encodedJson) {
5960
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
6061
}
6162

src/Symfony/Component/Serializer/Tests/Encoder/JsonEncoderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public function testOptions()
6565
$this->assertEquals($expected, $this->serializer->serialize($arr, 'json'), 'Context should not be persistent');
6666
}
6767

68+
/**
69+
* @require PHP 5.5
70+
*/
71+
public function testPartialJson()
72+
{
73+
$context = array('json_encode_options' => JSON_PARTIAL_OUTPUT_ON_ERROR);
74+
75+
$this->assertEquals('0', $this->serializer->serialize(NAN, 'json', $context));
76+
}
77+
6878
protected function getJsonSource()
6979
{
7080
return '{"foo":"foo","bar":["a","b"],"baz":{"key":"val","key2":"val","A B":"bar","item":[{"title":"title1"},{"title":"title2"}],"Barry":{"FooBar":{"Baz":"Ed","@id":1}}},"qux":"1"}';

0 commit comments

Comments
 (0)
0