Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83d2f6d

Browse files
committed
[Serializer] Fixed throwing exception with option JSON_PARTIAL_OUTPUT_ON_ERROR.
1 parent e77545a commit 83d2f6d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ public function decode($data, $format, array $context = array())
9595
$decodedData = json_decode($data, $associative, $recursionDepth);
9696
}
9797

98-
if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
99-
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
98+
if (false === $decodedData){
99+
$this->lastError = json_last_error();
100+
throw new UnexpectedValueException(
101+
sprintf('Json decode error #%s: %s', json_last_error(), json_last_error_msg())
102+
);
100103
}
101104

102105
return $decodedData;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ 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()) {
59-
throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
58+
if (false === $encodedJson){
59+
$this->lastError = json_last_error();
60+
throw new UnexpectedValueException(
61+
sprintf('Json encode error #%s: %s', json_last_error(), json_last_error_msg())
62+
);
6063
}
6164

6265
return $encodedJson;

0 commit comments

Comments
 (0)