3

I’m trying to use apigility with doctrine’s mongodb odm.
I’ve set up my documents and configured the doctrine module as should.
I’ve inserted (manually) one document to mongo, and defined a code-based rest service, with its “fetch” method (in the resource class) to return the document's repository "find" return value.

When I call the endpoint (without the ID) I get an array of the single document I’ve inserted, but it’s not shown correctly:

{
  "_links": {
    "self": {
      "href": "http://localhost:8888/posts"
    }
  },
  "_embedded": {
    "posts": [
      {
        "\u0000MyApp\\Document\\Post\u0000id": "5389db47075000812e55bd7d",
        "\u0000MyApp\\Document\\Post\u0000title": "My Post",
        "\u0000MyApp\\Document\\Post\u0000description": "This is my post",
        "_links": {
          "self": {
            "href": "http://localhost:8888/posts/1"
          }
        }
      }
    ]
  },
  "total_items": 1
}

There are (at least) two problems with this output:

  1. The key of each property is weirdly formatted. it contains the complete namespace with the document name, and the utf8 code for NULL
  2. The “self” link does not use the correct id (it uses the number 1 instead of the mongodb autogenerated id).

What is wrong/missing ?

Doron
  • 3,176
  • 7
  • 35
  • 60
  • Are you sure your `App\Document\Post` entity is declared in `zf-rest`'s configuration (under the controller's `entity_name` key), and in `zf-hal`'s `metadata_map` configuration? If all is OK, the entity's hydrator can be changed (`zf-hal.metadata_map.App\Document\Post.hydrator` or, if none, `zf-hal.renderer.default_hydrator`) and/or a custom hydration strategy can be set using ZF2's `HydratorManager`. – Stock Overflaw Jun 21 '14 at 21:55

1 Answers1

0

This happens when php uses ObjectProperty (\Zend\Stdlib\Hydrator\ObjectProperty )hydrator for populating the Objects.And in Apigility if you dont specify a hydrator then it will fall back to ObjectProperty hydrator(Default), which seems to be the case with your ouput. Use Classmethods hydrator (\Zend\Stdlib\Hydrator\ClassMethods) instead.