Serializer

Using a custom serializer with DrupalClient.


The NextDrupalPages uses jsona as the default serializer for serializing and deserializing JSON:API data.

You can provide your own using the serializer option.


Example

Here's how you can replace the default serializer with jsonapi-serializer.

lib/drupal.ts

import { NextDrupalPages } from "next-drupal"
import { Deserializer } from "jsonapi-serializer"
// Create a custom serializer.
const customSerializer = new Deserializer({
keyForAttribute: "camelCase",
})
// Pass the custom serializer to the client.
export const drupal = new NextDrupalPages(
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
{
serializer: customSerializer,
}
)