Skip to content

Incorrect serialization of zod objects with complex types (transform, refine,...) #172

@Tom-DK

Description

@Tom-DK

Hi there,

I'm working with complex dates, because our app requires timezone dependent functionality.

So I have custom transformations like this one:
startDate: z.string().transform(date => DateTime.fromFormat(date, 'yyyy-MM-dd')),

Expected scenario

startDate is serialized like: '2025-01-01'

What actually happens

Transformation already runs on the client side and calls the toString() function of DateTime leading to a serialized string value of "2025-01-01T00:00:00+1"

Zod makes a distinction between input and output types, the transformation should only occur on the backend. React-hook-forms supports this like this: https://github.com/orgs/react-hook-form/discussions/8496#discussioncomment-8800129

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions