Skip to content

fix(serializer): collection denormalization from object linked to doctrine entities #4301

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
wants to merge 1 commit into from

Conversation

nicodmf
Copy link

@nicodmf nicodmf commented Jun 1, 2021

Q A
Branch? current
Type Bug fix
Tickets no
License MIT

As it, denormalization doesn't find the children class in this case :

// Class to denormalize, not an entity, just an input class from a operation with messenger=input
class X {
  // id, other props not mentionned here ...
  /** @var Entity[] */
  public $collection;
}

// Object receive in json-ld
['collection'=>[{"@id"=>"/entities/5"}]]
// Object receive in json
['collection'=>[{"id"=>5}]]

If $entity has an id like in the example, object is denormalized normally with json ld ("@id": "iri"). With json format, the resource_class is absent from context and the object is denormalized without database populate and losing the id value. This fix come from parent class https://github.com/api-platform/core/blob/2.6/src/Serializer/AbstractItemNormalizer.php#L187 which will be call after the populate.

@nicodmf nicodmf changed the title fix(serializer) collection denormalization from object linked to doctrine entities fix(serializer): collection denormalization from object linked to doctrine entities Jun 1, 2021
@norkunas
Copy link
Contributor

norkunas commented Jun 1, 2021

Why don't you send IRI's for json format?

@nicodmf
Copy link
Author

nicodmf commented Jun 1, 2021

to be consistent with response which give not an iri but an numeric id. I just try with iri, same result

@nicodmf
Copy link
Author

nicodmf commented Jun 1, 2021

i just see #2326, this fix isn't aware for all cases, neither last PR... The logger don't work too and provide a NullLogger.

So, what do you think about a fix working in all cases ?

@soyuka
Copy link
Member

soyuka commented Jun 4, 2021

I need to understand the use case behind it, not sure this is expected behavior

@nicodmf
Copy link
Author

nicodmf commented Jun 8, 2021

@soyuka The use case is the send of many objects which should be received together because each change on the system has important cost. Send objects together permit to validate all changes and to transmit computional operations in one pass.

The object to deserialize looks like

{
  rules: [
   {id: '', period: xx, type: "", values: [ {id, value, populationTarget} ] },
   {id: '', period: xx, type: "", values: [ {id, value, populationTarget} ] }
  ]
}

I found a workarround with a dedicated resource and messager=true. But actually, it remains the logger bug which is a NullLogger.

@soyuka
Copy link
Member

soyuka commented Jun 8, 2021

mb related #1645

@nicodmf nicodmf closed this Nov 3, 2021
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

Successfully merging this pull request may close these issues.

4 participants