-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Missing documentation to register a new encoder #994
Comments
in your case if you want this to work with your custom 'myformat' format, then just update your encoder because right now public function supportsEncoding(string $format): bool
{
return self::FORMAT === $format;
}
public function supportsDecoding(string $format): bool
{
return self::FORMAT === $format;
} Then once your encoder will be able to respond correctly you should be good. |
Many thanks for the trick. The functions have to be slightly modified to be compatible with
I'll will test the custom format tomorrow and then work on a pull request to describe the custom encoder registration process in the content negociation API Platform documentation. |
that depends on your Symfony version actually 🤣 |
I'm trying to register a new encoder following the https://api-platform.com/docs/core/content-negotiation/ Supporting custom format example.
However, I get a
"Serialization for the format myformat is not supported"
when accessing API Platform after having followed the documented example.Step 1 : Created a custom encoder class following the https://symfony.com/doc/current/serializer/custom_encoders.html documentation
For the test and to match the reference documentation, the encoder returns a yaml content.
It is not clear at all in the documentation how to link the myformat new format with the
MyFormatEncoder
class. I used theconst FORMAT = 'myformat';
to miror how the XML encoder class is created, but I might be wrong.Step 2 : Registered the custom encoder class following the https://symfony.com/doc/current/serializer/custom_encoders.html documentation using the serializer.encoder tag
Step 3 : Registered custom format in api_platform.yaml
An update of https://api-platform.com/docs/core/content-negotiation/ might be required to beter describe how to register a custom API Platform encoder as the https://symfony.com/doc/current/serializer.html#adding-normalizers-and-encoders and https://symfony.com/doc/current/serializer/custom_encoders.html are not clear at all about the new encoder and format registration process.
The text was updated successfully, but these errors were encountered: