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

Support for java.time.Year (and possibly other time types as well) #2856

Open
peholmst opened this issue Oct 22, 2024 · 5 comments
Open

Support for java.time.Year (and possibly other time types as well) #2856

peholmst opened this issue Oct 22, 2024 · 5 comments
Labels
enhancement New feature or request hilla Issues related to Hilla needs design

Comments

@peholmst
Copy link
Member

Describe your motivation

I'd like to be able to use java.time.Year in browser callable services, and possibly other time types as well. Many business applications work with time in various ways and so it would make sense to support this in Hilla as well.

Without any custom configuration, Jackson serializes Year as a string. Hilla is able to read this as well. However, the model type is ObjectModel and the DTO type is unknown. This causes problems with form binding; the default empty value is [object Object] and not an empty string.

Describe the solution you'd like

A quick and dirty solution would be to just hard code support for java.time.Year and other built-in Java types that one could assume are used in browser callable services.

A more flexible solution would be an API for customizing the code generator. Just as you have to create a custom serializer and deserializer to instruct Jackson to treat Year as an integer, you could create a custom converter that instructs the Hilla code generator how to treat Year.

Describe alternatives you've considered

You could just use an integer or string in your DTO and handle the conversion inside the browser callable service. However, this goes agains the principle of being able to use the same backend in both Flow and Hilla.

This turns the browser callable services into adapters - yet another abstraction layer in front of the actual application services.

Additional context

No response

@peholmst peholmst added enhancement New feature or request hilla Issues related to Hilla labels Oct 22, 2024
@platosha
Copy link
Contributor

Regarding the API for customizing the code generator, one solution would be better exposure for the Jackson mapper that we use in both code generation and runtime.

For now let us go with hard-coded java.time.Year support.

@platosha
Copy link
Contributor

What about other java.time.* classes? Any other common missing types?

@peholmst
Copy link
Member Author

java.time.YearMonth would be useful, as would java.time.Period and java.time.Duration. I assume LocalDate, LocalDateTime, ZonedDateTime, OffsetDateTime, and Instant are already supported.

@platosha
Copy link
Contributor

We need to define the scope for supported types somehow. Any good ideas for the baseline?

@peholmst
Copy link
Member Author

Maybe everything that Java provides out of the box should be supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hilla Issues related to Hilla needs design
Projects
None yet
Development

No branches or pull requests

2 participants