-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
The yml format is not supported by the YamlEncoder #28768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Possible workaround with service decoration: namespace App\Serializer\Encoder;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
/**
* @see https://github.com/symfony/symfony/issues/28768
*/
final class YamlEncoder implements EncoderInterface, DecoderInterface
{
private const FORMAT = 'yml';
/**
* @var \Symfony\Component\Serializer\Encoder\YamlEncoder
*/
private $encoder;
public function __construct(\Symfony\Component\Serializer\Encoder\YamlEncoder $encoder)
{
$this->encoder = $encoder;
}
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array())
{
return $this->encoder->encode($data, $format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format)
{
return $this->encoder->supportsEncoding($format) || self::FORMAT === $format;
}
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = array())
{
return $this->encoder->decode($data, $format, $context);
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format)
{
return $this->encoder->supportsDecoding($format) || self::FORMAT === $format;
}
} services:
App\Serializer\Encoder\YamlEncoder:
decorates: serializer.encoder.yaml |
This looks too restrictive to me too. I think we should support |
AFAIK, the |
This is not the direct issue, but API system like FOSRest will use it. If you call Am I wrong? |
API Platform does it too. But in this case, it's better to add an adapter in FOSRest/API Platform to pass |
Yml is so common and non-ambiguous that I'd be fine supporting it out of the box personally. |
This PR was merged into the 4.2-dev branch. Discussion ---------- YamlEncoder handle yml format | Q | A | ------------- | --- | Branch? | ? | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28768 | License | MIT `Symfony\Component\Serializer\Encoder\YamlEncoder` now handle the `yml` format too ``` use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Encoder\YamlEncoder; $serializer = new Serializer([], [new YamlEncoder()]); $content = file_get_contents(__DIR__ . '/test.yml'); $data = $serializer->decode($content, YamlEncoder::ALTERNATIVE_FORMAT); ``` Let me know if something is wrong for you Commits ------- d8640f9 YamlEncoder handle yml extension
Symfony version(s) affected: 4.1.6
Description
The
YamlEncoder
currently support only theyaml
format:symfony/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
Line 25 in cbe2895
AFAIK, the
.yml
file format is also accepted for Yaml format. IMO, it should be added to the support of this encoder.The text was updated successfully, but these errors were encountered: