File tree 1 file changed +8
-3
lines changed
src/Symfony/Component/Serializer/Encoder
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,19 @@ public function __construct($bitmask = 0)
35
35
public function encode ($ data , $ format , array $ context = [])
36
36
{
37
37
$ context = $ this ->resolveContext ($ context );
38
+ $ options = $ context ['json_encode_options ' ];
38
39
39
- $ encodedJson = json_encode ($ data , $ context ['json_encode_options ' ]);
40
+ try {
41
+ $ encodedJson = json_encode ($ data , $ options );
42
+ } catch (\JsonException $ e ) {
43
+ throw new NotEncodableValueException ($ e ->getMessage (), 0 , $ e );
44
+ }
40
45
41
- if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $ context [ ' json_encode_options ' ] )) {
46
+ if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $ options )) {
42
47
return $ encodedJson ;
43
48
}
44
49
45
- if (JSON_ERROR_NONE !== json_last_error () && (false === $ encodedJson || !($ context [ ' json_encode_options ' ] & JSON_PARTIAL_OUTPUT_ON_ERROR ))) {
50
+ if (JSON_ERROR_NONE !== json_last_error () && (false === $ encodedJson || !($ options & JSON_PARTIAL_OUTPUT_ON_ERROR ))) {
46
51
throw new NotEncodableValueException (json_last_error_msg ());
47
52
}
48
53
You can’t perform that action at this time.
0 commit comments