Skip to content

[Serializer] Encoder options from the framework bundle #28771

Closed
@soullivaneuh

Description

@soullivaneuh

Description

AFAIK there is no way to provide a YamlEncoder default context or JsonEncoder json decoder service (with custom options) from configuration.

It would great to be able to do it.

Example

framework:
    serializer:
        name_converter: serializer.name_converter.camel_case_to_snake_case
        encoders:
             yaml:
                  inline: 10

Possible Workaround

On the kernel, overwrite the definitions (example with the yaml encoder):

final class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

// ...

    public function process(ContainerBuilder $container): void
    {
        $container->getDefinition('serializer.encoder.yaml')
            ->setArguments([null, null, [
                'yaml_inline' => 10,
            ]])
        ;

// ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions