- if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) {
- throw new UnexpectedValueException(json_last_error_msg());
+ if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
+ throw new NotEncodableValueException(json_last_error_msg());