-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: id
is set to exclude attribute in deserialization and still included as undefined
#69
Comments
Correct me if I'm wrong, but I think |
@stefanvanherwijnen I can understand your reasoning behind letting the If an attribute is blacklisted, doesn't it mean it should completely be erased from output? Because if it is not the case, it will force users to add an extra util function or a replacement to correctly filter the intended blacklisted attributes, as I had to do. For example, in my case, setting If a full exclusion wasn't the intended outcome with the blacklist feature, maybe can you add an extra Thanks. |
The problem is that id is not an The ID and attributes are handled differently in the source code, so applying a attribute blacklist to the ID will be more complicated than just filtering the result. |
Please, bear with be for pushing on this, I just think that this has to be baked in the module instead of being in user ground. All this time since I added the issue I've been using a simple filtering solution like the one you stated, I'm only discussing here that the blacklist feature should be global to all properties of the final object, including Maybe this can be a separate boolean flag to include or not I do understand that Hope this makes sense and you understand me, again, sorry for pushing on this, but makes perfect sense to me to have it baked in. Nevertheless, if you still think that this has to be on user land, ok, we can close the issue and continue just like we were now :) |
Actually, you are right and this has nothing to do with This is how the id is handled: json-api-serializer/lib/JSONAPISerializer.js Line 380 in e346ab5
As you can see a few lines beneath it, the attributes are neatly picked and omitted according to the blacklist. To blacklist/whitelist the id, you could do something like this:
This works, but it's not exactly a neat solution 🙄 . So, unless @danivek intentionally designed it such that blacklist only works on attributes (as the documentation says: An array of blacklisted attributes), I agree this is a bug. But the question is how to solve it neatly. |
Awesome! Well, we just need to wait until @danivek states his opinion on the approach for its implementation (if he agrees). In the meantime, I will continue filtering after deserialization logic. Thanks @stefanvanherwijnen! |
@diosney what about having just a check on if (data.id !== undefined) {
deserializedData[options.id] = data.id;
} instead of: json-api-serializer/lib/JSONAPISerializer.js Line 380 in e346ab5
So if you would not provide an id, you would not end up with the id in the deserialized data instead of undefined. |
@danivek What I was really asking for is for a way to enforce a blacklist/filtering of Thanks |
@danivek Would you be ok w/ this specific fix? I have it as a patch in my codebase for a long time. |
@medfreeman I'm ok with this fix |
@medfreeman It is something, but is not what I ultimately expect, sorry. If I blacklist it, it mustn't be in the final output, IMHO. |
Do we all agree that the id property should be absent from the output anyway? @diosney i agree with you about the feature you're requesting, but i think these can be considered as two separate issues. I'll then submit a PR that won't close your issue though. |
I've setup:
But still on deserialization is giving me
id = undefined
since I'm not sending it, though I want to exclude it completely from deserialization.The text was updated successfully, but these errors were encountered: