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

Specify @Serializer/Group for @Discriminator field #506

Closed
thaonx opened this Issue Mar 3, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@thaonx

thaonx commented Mar 3, 2016

This is a example code. How to add "type" filed into a specific group ?

<?php
namespace Entity;
use JMS\Serializer\Annotation as JMS;
/**
 * @JMS\Discriminator(field = "type", map = {
 *    "user": "Entity\User",
 *    "mod": "Entity\Moderator"
 * })
 */
abstract class AbstractUser
{
  /**
   * @JMS\Type("integer")
   */
  public $id;
  /**
   * @JMS\Type("string")
   */
  public $name;
  /**
   * @JMS\Type("string")
   */
  public $type;
}
@lordelph

This comment has been minimized.

Show comment
Hide comment
@lordelph

lordelph Mar 4, 2016

I've just run into a similar issue - if I'm using groups, then the discriminator will not appear in the serialized data.

I found that if my serialization context contained 'Default', then the discriminator will appear. So, one workaround is to ensure that all fields either have groups or are excluded, and always serialized with a context of Default + whatever groups you want.

It would be nice if there was a way to specify which groups the discriminator should appear in.

lordelph commented Mar 4, 2016

I've just run into a similar issue - if I'm using groups, then the discriminator will not appear in the serialized data.

I found that if my serialization context contained 'Default', then the discriminator will appear. So, one workaround is to ensure that all fields either have groups or are excluded, and always serialized with a context of Default + whatever groups you want.

It would be nice if there was a way to specify which groups the discriminator should appear in.

@thaonx thaonx changed the title from Cannot add @Discriminator field into specific @Serializer/Group to Specify @Serializer/Group for @Discriminator field Mar 29, 2016

@VBelozyorov

This comment has been minimized.

Show comment
Hide comment
@VBelozyorov

VBelozyorov Mar 29, 2016

Same here. Thank you @lordelph for the workaround.

VBelozyorov commented Mar 29, 2016

Same here. Thank you @lordelph for the workaround.

@goetas

This comment has been minimized.

Show comment
Hide comment
@goetas

goetas Dec 3, 2016

Collaborator

solved with schmittjoh/serializer#579, will be included in v1.5

Collaborator

goetas commented Dec 3, 2016

solved with schmittjoh/serializer#579, will be included in v1.5

@goetas goetas closed this Apr 3, 2017

@patie

This comment has been minimized.

Show comment
Hide comment
@patie

patie Apr 9, 2017

@goetas i think this is not solved, im using newest version and i have same issue

@lordelph have you better solution now?

patie commented Apr 9, 2017

@goetas i think this is not solved, im using newest version and i have same issue

@lordelph have you better solution now?

@goetas

This comment has been minimized.

Show comment
Hide comment
@goetas

goetas Apr 9, 2017

Collaborator

@patie can you submit a failing test case?

Collaborator

goetas commented Apr 9, 2017

@patie can you submit a failing test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment