diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 9286dd0890de2..8072319b5eaf7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * Add native return type to `Translator` and to `Application::reset()` * Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false` + * Enable `json_decode_detailed_errors` context for Serializer by default if `kernel.debug` is true and the `seld/jsonlint` package is installed 6.3 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index e1063b37eccba..0e277cf2cdc46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -14,6 +14,7 @@ use Doctrine\Common\Annotations\Annotation; use Doctrine\DBAL\Connection; use Psr\Log\LogLevel; +use Seld\JsonLint\JsonParser; use Symfony\Bundle\FullStack; use Symfony\Component\Asset\Package; use Symfony\Component\AssetMapper\AssetMapper; @@ -41,6 +42,7 @@ use Symfony\Component\RemoteEvent\RemoteEvent; use Symfony\Component\Scheduler\Schedule; use Symfony\Component\Semaphore\Semaphore; +use Symfony\Component\Serializer\Encoder\JsonDecode; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Translation\Translator; use Symfony\Component\Uid\Factory\UuidFactory; @@ -1123,6 +1125,10 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e ->arrayNode('default_context') ->normalizeKeys(false) ->useAttributeAsKey('name') + ->beforeNormalization() + ->ifTrue(fn () => $this->debug && class_exists(JsonParser::class)) + ->then(fn (array $v) => $v + [JsonDecode::DETAILED_ERROR_MESSAGES => true]) + ->end() ->defaultValue([]) ->prototype('variable')->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index e3ecd982d3cc8..7dee7fc5c0ef1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -27,6 +27,7 @@ use Symfony\Component\Notifier\Notifier; use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter; use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory; +use Symfony\Component\Serializer\Encoder\JsonDecode; use Symfony\Component\Uid\Factory\UuidFactory; class ConfigurationTest extends TestCase @@ -34,7 +35,7 @@ class ConfigurationTest extends TestCase public function testDefaultConfig() { $processor = new Processor(); - $config = $processor->processConfiguration(new Configuration(true), [['http_method_override' => false, 'secret' => 's3cr3t']]); + $config = $processor->processConfiguration(new Configuration(true), [['http_method_override' => false, 'secret' => 's3cr3t', 'serializer' => ['default_context' => ['foo' => 'bar']]]]); $this->assertEquals(self::getBundleDefaultConfig(), $config); } @@ -563,8 +564,8 @@ protected static function getBundleDefaultConfig() 'enabled' => true, ], 'serializer' => [ - 'default_context' => [], - 'enabled' => !class_exists(FullStack::class), + 'default_context' => ['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => true], + 'enabled' => true, 'enable_annotations' => !class_exists(FullStack::class), 'mapping' => ['paths' => []], ], diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 1a27839a47186..2a33d8751a088 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -35,6 +35,7 @@ "require-dev": { "doctrine/annotations": "^1.13.1|^2", "doctrine/persistence": "^1.3|^2|^3", + "seld/jsonlint": "^1.10", "symfony/asset": "^5.4|^6.0|^7.0", "symfony/asset-mapper": "^6.3|^7.0", "symfony/browser-kit": "^5.4|^6.0|^7.0", @@ -58,7 +59,7 @@ "symfony/scheduler": "^6.3|^7.0", "symfony/security-bundle": "^5.4|^6.0|^7.0", "symfony/semaphore": "^5.4|^6.0|^7.0", - "symfony/serializer": "^6.3|^7.0", + "symfony/serializer": "^6.4|^7.0", "symfony/stopwatch": "^5.4|^6.0|^7.0", "symfony/string": "^5.4|^6.0|^7.0", "symfony/translation": "^6.2.8|^7.0", @@ -90,7 +91,7 @@ "symfony/mime": "<6.2", "symfony/property-info": "<5.4", "symfony/property-access": "<5.4", - "symfony/serializer": "<6.3", + "symfony/serializer": "<6.4", "symfony/security-csrf": "<5.4", "symfony/security-core": "<5.4", "symfony/stopwatch": "<5.4",