SeyZ / jsonapi-serializer

A Node.js framework agnostic library for (de)serializing your data to JSON API
MIT License
735 stars 196 forks source link

'Type' property is lost after deserialize #180

Open rubenkuipers opened 6 years ago

rubenkuipers commented 6 years ago

In our api we user the type property to define types of resources. But when I deserialize the data from the back-end, the type property gets lost from the data. Is this natural behaviour/best practice? Because they're useful to us for filtering and separating types of resources in our client app.

Input:

{
  "data": {
    "type": "residence_project",
    "id": "ea9872e0-8e03-4e45-a992-f86a12989937",
    "attributes": {
      "title": "Test",
      "description": null,
      "state": "pending_available",
      "accountId": "40ddc4cc-a1d9-4bee-a633-a57ae6227649",
      "agentIds": [],
      "createdAt": "2018-07-11T10:24:04+02:00",
      "updatedAt": null
    }
  },
  "meta": {
    "requestId": "73f50732-d155-46cc-90f0-ed1c7615b578"
  }
}

Usage:

const deserializer = new Deserializer({
  keyForAttribute: 'camelCase'
});

deserializer.deserialize(data)

Output:

{
  "data": {
    "title": "OSRE Dev 2",
    "description": null,
    "state": "pending_available",
    "accountId": "40ddc4cc-a1d9-4bee-a633-a57ae6227649",
    "agentIds": [],
    "createdAt": "2018-07-11T10:24:04+02:00",
    "updatedAt": null,
    "id": "ea9872e0-8e03-4e45-a992-f86a12989937"
  },
  "requestId": "755a6a69-5c84-4e30-b831-f4dcd2f72f6f"
}
pedrofernandezm commented 6 years ago

@kuiperr005 I was having the same issue. The solution is here