Skip to content
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

When I use java.util.Date as a class param, I got an serialization issue. #204

Closed
sustainjane98 opened this issue Dec 24, 2022 · 1 comment

Comments

@sustainjane98
Copy link

When I create a data class like this:

data class Person(
    val firstname: String,
    val lastname: String,
    val age: Int,
    val birthdate: Date
)

And thewn create a query resolver like this:

fun SchemaBuilder.person() {
    query("me") {
        resolver {
            ->
            Person("Hans", "Meier", 24, Date.valueOf(LocalDate.parse("1998-02-12")))
        }
    }
}

I get the following error:

An Object type must define one or more fields. Found none on type Date

Is there any way to tell the framework to use a custom serializer, to fix this?

@sustainjane98
Copy link
Author

You can write a custom serializer in the schema like that:

fun SchemaBuilder.serializerDate() {
    longScalar<Date> {
        serialize = { date -> date.time }
        deserialize = { dateString -> Date(dateString) }
    }
}

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

1 participant