Problem/Motivation

Having entity exposed through the rest module it is currently not possible to update an entity using the JSON format while hal+json does.
This is due to how the denormalizers for those two formats work.

The hal denormalizer extracts the entity form the _links section, the JSON denormalizer needs the entity type provided in a context array.

The rest module does not provide that context when entities are unserialized.

Proposed resolution

tbd

Remaining tasks

  • Write tests that verify that CRUD of content entities works with all serialization formats supported by core

User interface changes

Not UI components involved.

API changes

tbd

Original report by [corvus_ch]

PATCH /node/1
Accept: application/json
X-CSRF-Token:  *****-*************************************
Content-Type: application/json

{ "title": [ { "value": "Cras justo odio, dapibus ac facilisis in, egestas eget quam." } ] }

Then I get:

HTTP/1.1 400 Bad Request
Content-Type →application/json

{
    "error": "Entity type parameter must be included in context."
}

While this works using application/hal+json (which needs the entity type to be defined in _links section), it does not for json. The JSON denormalizer requires that the entity type is passed in via the context argument.

The RequestHandler does only provide the request method through the context argument.

CommentFileSizeAuthor
#1 Bad Pathc.png73.39 KBvivekvpandya
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vivekvpandya’s picture

FileSize
73.39 KB

I am also agree with this because once you have already created a node then while updating it should not require to provide type "_links" with hal+json. Only json should work for this purpose.

clemens.tolboom’s picture

@vivekvpandya your image is not adding information :-(

It would be great to have a script with curl commands added to the issue summary.

[Stock response from Dreditor templates and macros.]

Please update the issue summary by applying the template from http://drupal.org/node/1155816.

corvus_ch’s picture

Issue summary: View changes
clemens.tolboom’s picture

@corvus_ch nice work :-)

Do you mind to add the shell commands for this?

See https://www.drupal.org/documentation/modules/rest in particular https://www.drupal.org/node/2098511

clemens.tolboom’s picture

Status: Active » Closed (duplicate)
Parent issue: » #1964034: Pass entity_type into Serializer via context