1

This question is an exact duplicate of:

So I created my own RestResource, like so:

/**
 * Provides a resource to get/create content data.
 *
 * @RestResource(
 *   id = "mycontent_content",
 *   label = @Translation("My content"),
 *   uri_paths = {
 *     "canonical" = "/api/content/{type}",
 *     "https://www.drupal.org/link-relations/create" = "/api/content/{type}"
 *   }
 * )
 */
class ContentResource extends ResourceBase {

    public function get($type) {
        // Works
    }

    public function post($type) {
        // Doesn't work
    }
}

GET works fine, but I can not post a regular JSON object.

With the content-type set to application/json I always get this error:

{
    "error": "Could not denormalize object of type , no supporting normalizer found."
}

I guess it's trying to create an entity out of it, but that's not what it is. I just want the damn JSON object as it is.

Is there some way to do this?

marked as duplicate by kiamlaluno Jul 29 '16 at 11:00

This question was marked as an exact duplicate of an existing question.

  • on top of the class file you need to call namespace Drupal\rest\Plugin\rest\resource; – vgoradiya Mar 30 '16 at 9:34
  • I removed my answer while I rethink it. Adding a comment here instead to mention that the answer was about the serialization_class part of the plugin definition. This may be necessary or maybe adding the default symfony normalizer as a tagged service. – mradcliffe Mar 30 '16 at 14:22

Browse other questions tagged or ask your own question.