Skip to content

ValidationError: beforeSerialize is not allowed #114

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

Closed
nrcmkoh opened this issue Aug 11, 2020 · 2 comments
Closed

ValidationError: beforeSerialize is not allowed #114

nrcmkoh opened this issue Aug 11, 2020 · 2 comments

Comments

@nrcmkoh
Copy link

nrcmkoh commented Aug 11, 2020

I'm seeing this error when try to set up a composite id:
ValidationError: beforeSerialize is not allowed

Here's my code to register the types. Note that I am not getting an error to serialize the other relationship locationGoals, which doesn't use beforeSerialize():

      serializer.register('client', {
        id: 'id',
        relationships: {
          alertingAccesses: { type: 'alerting-accesses' },
          locationGoals: { type: 'location-goals' },
        },
      });

      serializer.register('alerting-accesses', {
        beforeSerialize: (data) => {
          return { ...data, id: `${data.realtimeUserId}_${data.clientId}` };
        },
      });

      serializer.register('location-goals', {
        id: 'id',
      });

I've used beforeSerialize() on other occasions without running into this error, so I'm not sure why it's happening here.

json-api-serializer version: 2.5.0

@danivek
Copy link
Owner

danivek commented Aug 11, 2020

ValidationError comes from the joi package which was used on version lower than 2.0.0.
As of 2.0.0 it no longer uses joi, so you shouldn't get this error.

Please check your version of json-api-serializer

@nrcmkoh
Copy link
Author

nrcmkoh commented Aug 11, 2020

It looks like I had a stale version of this package in my node_modules folder because my package.json has this in it:
image

I manually removed the package and ran npm install, and everything appears to be working now. Thanks!

@nrcmkoh nrcmkoh closed this as completed Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants