Skip to content
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

JSON Serialization Options seem to be ignored #763

Closed
Vorta opened this issue Jul 25, 2019 · 5 comments
Closed

JSON Serialization Options seem to be ignored #763

Vorta opened this issue Jul 25, 2019 · 5 comments

Comments

@Vorta
Copy link

Vorta commented Jul 25, 2019

Symfony: v4.3.2
willdurand/hateoas: v3.1.0
jms/serializer: v3.1.1
jms/serializer-bundle: v3.4.1

I may be missing something, however I've noticed that I'm getting escaped slashes in my serialized output, even though my config looks as follows:

jms_serializer:
    visitors:
        xml_serialization:
            format_output: '%kernel.debug%'
            encoding: 'UTF-8'
        json_serialization:
            options: ['JSON_PRETTY_PRINT', 'JSON_UNESCAPED_SLASHES']

I've tried setting options: in other ways too:

   ...
            options:
                - JSON_PRETTY_PRINT
                - JSON_UNESCAPED_SLASHES

If I deliberately mistype a key, I get an error, so it shows that they are being read. However, the output is not being changed. Slashes are escaped and pretty print is not being performed.

If I dump $options in JsonSerializationVisitor.php, I can see that only the default JSON_PRESERVE_ZERO_FRACTION flag is being used. I have tried to find where are Options from the config being used, however, I was unsuccessful.

@goetas
Copy link
Collaborator

goetas commented Jul 25, 2019

hmm. weird. can you check which params are received by the https://github.com/schmittjoh/serializer/blob/master/src/Visitor/Factory/JsonSerializationVisitorFactory.php ?

@Vorta
Copy link
Author

Vorta commented Jul 25, 2019

I can see that setOptions in JsonSerializationVisitorFactory.php is not being called at any point.

However, https://github.com/schmittjoh/JMSSerializerBundle/blob/master/DependencyInjection/JMSSerializerExtension.php#L199 - This line does get executed and it gets correct parameter.

@goetas
Copy link
Collaborator

goetas commented Jul 25, 2019

I see that you are using willdurand/hateoas (but you did not mention its bundle), are you using the hateoas builder or the provided bundle integration? (99% the problem lies there :) )

@Vorta
Copy link
Author

Vorta commented Jul 25, 2019

Yes, willdurand/hateoas-bundle v2.0.1. I will check if it builds own instance of JMS serializer, ignoring the options.

@Vorta
Copy link
Author

Vorta commented Jul 25, 2019

Correct, Hateoas was actually the cause. Thank you for your time, and my apologies for a false alarm!

@Vorta Vorta closed this as completed Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants