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

why there is backslash ? #709

Closed
PauchardThomas opened this issue Dec 13, 2018 · 3 comments
Closed

why there is backslash ? #709

PauchardThomas opened this issue Dec 13, 2018 · 3 comments

Comments

@PauchardThomas
Copy link

S3.4
jms dev-master, 3.0.x-dev

Hello,

I would like to know why when I add groups, my response has backslashs like
"{\"items\":[{\"id\":100,\"content\":\" Hello !!\",\"created_on\":\"2018-12-11T15:57:12+01:00\",\"attribute\":true},{\"id\":101,\"content\":\"Test\",\"created_on\":\"2018-12-12T09:15:35+01:00\",\"attribute\":false}]}"

instead of

"{"items":[{"id":100,"content":" Hello !!","created_on":"2018-12-11T15:57:12+01:00","attribute":true},{"id":101,"content":"Test","created_on":"2018-12-12T09:15:35+01:00","attribute":false}]}"

Is there a way to remove them ?

Btw, when I get the reponse with newtonsoft json (c# library) I get triple backslashs which is pretty weird.

thank you.

@goetas
Copy link
Collaborator

goetas commented Dec 13, 2018

well, it depends how do you output the json...

@PauchardThomas
Copy link
Author

Sorry what do you mean ?

@PauchardThomas
Copy link
Author

I finaly found whats wrong. In my api rest I replace :

return $this->get('jms_serializer')->serialize($message, 'json',
            SerializationContext::create()->setGroups(array(
                'detail_discussion'
            )));

By :

        $data = $this->get('jms_serializer')->serialize($message, 'json',
            SerializationContext::create()->setGroups(array(
                'detail_discussion'
            )));
        
        $response = new Response($data);
        $response->headers->set('Content-Type', 'application/json');
        
        return $response;

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