andersondanilo / jsonapi-fractal

JSON:API Serializer inspired by Fractal (PHP)
MIT License
56 stars 14 forks source link

Support type in deserialized data #138

Open Ayc0 opened 4 months ago

Ayc0 commented 4 months ago

When running this code:

const serializedData = {
    data: {
        type: 'articles',
        id: '1',
        attributes: {
            type: 'articles',
            type: '123',
            title: 'JSON:API paints my bikeshed!',
        },

    },
};

deserialize(serializedData);

we get


{
  "id": "1",
  "type": "123",
  "title": "JSON:API paints my bikeshed!"
}

The type articles gets lost in the deserialization process. And I don't think we can just pass it top level as this could conflict with a attributes.type field.

What do you think about adding something like Symbol('type')? (would avoid conflicts and give access to the types)

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.

Ayc0 commented 2 months ago

Not stale

github-actions[bot] commented 3 hours ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.