Could not denormalize object of type , no supporting normalizer found.

I tried to create a custom Rest API with Drupal 8 and it was working great with GET operations. Problem is I wanted more, what about POST, PATCH, PUT, DELETE, … operations ?

Only GET examples were found about Drupal Rest API and nobody had any explanation about this POST response error:

Could not denormalize object of type , no supporting normalizer found.

So I had a look in Drupal Core and found out you need this interesting serialization_class comment annotation. Example with EntityResource:

Actually, if you implement GET, you don’t need this serialization_class to be filled because you only deal with primitive types, but if you want to implement something else like POST, PUT, …, this should be filled with an EntityType so Drupal would be able to understand and cast your parameters to the destination Entity.

Example, you create a VoteEntity and you need to implement GET and POST Rest apis, this should do the trick:

 

Hope this helps.

One Thought on “Could not denormalize object of type , no supporting normalizer found.

  1. MacSim on February 9, 2017 at 18:21 said:

    Hello,

    thank you for that post.
    I am wondering if there’s a way to use that post() function to add data in a custom table which is not following the Drupal 8 Entity schema.
    In other words can I create a serialization_class which is not extending a Drupal 8 class?
    If yes, what would that serialization_class looks like?

Leave a Reply to MacSim Cancel reply

Your email address will not be published.

Post Navigation