Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Deserialize json in AbstractController #38572

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

Closed
henry2778 opened this issue Oct 14, 2020 · 2 comments
Closed

[FrameworkBundle] Deserialize json in AbstractController #38572

henry2778 opened this issue Oct 14, 2020 · 2 comments

Comments

@henry2778
Copy link
Contributor

Description
Hi! Sorry in advance if that issue is a duplicate (didn't find anything like it). What if we add new method in AbstractController to deserialize from json (opposite to AbstractController::json()) ? AbstractController already has lots of methods, but still this opertation seem to be routine one while developing APIs :)

Example

protected function fromJson(string $body, string $to, array $context = [])
{
    // check if serializer available
    // return deserialized value
}

...

public function createUser(Request $request)
{
    $resource = $this->fromJson($request->getContent(), UserResource::class);
}

If OK, I would like to implement it.

WDYT? Thanks!

@derrabus
Copy link
Member

#38224 was added recently which allows fetching the JSON content of the response as array. But as far as I know, there's no shortcut for fetching the response content normalized into an instance of a specific class. But I'm not sure if the AbstractController is the right place for that.

@fabpot
Copy link
Member

fabpot commented Oct 14, 2020

I don't think this should be part of core. Thanks for proposing.

@fabpot fabpot closed this as completed Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants