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

Serialization profile/definition builder #68

Closed
Dynom opened this issue Mar 27, 2013 · 1 comment
Closed

Serialization profile/definition builder #68

Dynom opened this issue Mar 27, 2013 · 1 comment

Comments

@Dynom
Copy link

Dynom commented Mar 27, 2013

Hi,

I have a case where I'd like to specify properties/entities at runtime. Doing this using the groups tactic will result in a unwanted high maintenance situation. As a lot of groups need to be defined for many possible combinations. Unless groups is abused and a group is defined for every property. I guess that it's not only wanted, but also not the idea behind groups.

I would settle for a builder approach, something that the SerializationContext class might embrace. An idea is to introduce a certain profile/definition:

// Accept requirements from the request
$serializationProfile = SerializationProfile::create( $request->getParams() );

// Last-minute override
$serializationProfile->getRelation('orders')->exclude(array('profit'));

// just for demonstration
$serializationProfile->only(array('id', 'username', 'e-mail'));

// The actual serialization
$serializer->serialize($model, 'json', $serializationProfile);

This way it's trivial for a client to specify fields and optionally what resources to embed. Example:

/user/42?embed=address,orders.product&orders.product.properties=id,name

This should:

  • Include all the "addresses" this user has
  • Include all the "orders" this user has
  • Include the product id and name for each product in the order
@schmittjoh
Copy link
Owner

This is already possible using a custom exclusion policy.

If you can make a general implementation, feel free to open a PR with it.

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