Art4 / json-api-client

:construction_worker_woman: A PHP Library to handle the request or response body from a JSON API server.
GNU General Public License v3.0
138 stars 20 forks source link

Parsing listed resource: property "self" has to be a string, "object" given #26

Closed OskarD closed 8 years ago

OskarD commented 8 years ago

I am trying to parse a seemingly valid JSON Api response with ApiClient::parse that looks like this:

{
  "data": [
    {
      "type": "party",
      "id": "1",
      "attributes": {
        "legal_name": "Littel, Hickle and Wunsch",
        "legal_name_fetched": "2015-08-20 07:50:39",
        "nationality": "SE",
        "national_identifier": "5562404176",
        "created_at": "2016-04-13 13:39:25",
        "updated_at": "2016-04-13 13:39:25",
        "deleted_at": null
      },
      "links": {
        "self": {
          "href": "http://parties.api/v1/parties/1"
        }
      }
    },
    {
      "type": "party",
      "id": "2",
      "attributes": {
        "legal_name": "Crona, Jast and Bartell",
        "legal_name_fetched": "2015-09-25 04:10:47",
        "nationality": "SE",
        "national_identifier": "5560560748",
        "created_at": "2016-04-13 13:39:25",
        "updated_at": "2016-04-13 13:39:25",
        "deleted_at": null
      },
      "links": {
        "self": {
          "href": "http://parties.api/v1/parties/2"
        }
      }
    },
...
    {
      "type": "party",
      "id": "14",
      "attributes": {
        "legal_name": "Morar, O'Reilly and Rutherford",
        "legal_name_fetched": "2016-02-04 16:55:01",
        "nationality": "SE",
        "national_identifier": "5561933039",
        "created_at": "2016-04-13 13:39:25",
        "updated_at": "2016-04-13 13:39:25",
        "deleted_at": null
      },
      "links": {
        "self": {
          "href": "http://parties.api/v1/parties/14"
        }
      }
    },
    {
      "type": "party",
      "id": "15",
      "attributes": {
        "legal_name": "Jacobs-Herzog",
        "legal_name_fetched": "2016-04-03 04:26:40",
        "nationality": "SE",
        "national_identifier": "5562590205",
        "created_at": "2016-04-13 13:39:25",
        "updated_at": "2016-04-13 13:39:25",
        "deleted_at": null
      },
      "links": {
        "self": {
          "href": "http://parties.api/v1/parties/15"
        }
      }
    }
  ],
  "included": [],
  "links": {
    "self": {
      "href": "?page[number]=1&page[size]=10"
    },
    "first": {
      "href": "?page[number]=1&page[size]=10"
    },
    "next": {
      "href": "?page[number]=2&page[size]=10"
    },
    "last": {
      "href": "?page[number]=11&page[size]=10"
    }
  },
  "meta": {
    "page": {
      "total": 106,
      "last": 11,
      "number": 1,
      "size": 10
    }
  },
  "jsonapi": {
    "version": "1.0"
  }
}

But I am getting this error: Art\JsonApiClient\Exception\ValidationException: property "self" has to be a string, "object" given. thrown on line 66 in the DocumentLink class.

Why is this happening?

Art4 commented 8 years ago

Thank you for this issue. Seems like links aren't parsed correct. I'm working on a fix.

Art4 commented 8 years ago

Release 0.6.2 was published.