Skip to content

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

Closed
nicodmf wants to merge 1 commit into
api-platform:2.6from
nicodmf:2.6
Closed

fix(serializer): collection denormalization from object linked to doctrine entities#4301
nicodmf wants to merge 1 commit into
api-platform:2.6from
nicodmf:2.6

Conversation

@nicodmf

@nicodmf nicodmf commented Jun 1, 2021

Copy link
Copy Markdown
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

norkunas commented Jun 1, 2021

Copy link
Copy Markdown
Contributor

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

@nicodmf

nicodmf commented Jun 1, 2021

Copy link
Copy Markdown
Author

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

@nicodmf

nicodmf commented Jun 1, 2021

Copy link
Copy Markdown
Author

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

soyuka commented Jun 4, 2021

Copy link
Copy Markdown
Member

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

@nicodmf

nicodmf commented Jun 8, 2021

Copy link
Copy Markdown
Author

@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

soyuka commented Jun 8, 2021

Copy link
Copy Markdown
Member

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