Open peholmst opened 1 month ago
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.
What about other java.time.*
classes? Any other common missing types?
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.
We need to define the scope for supported types somehow. Any good ideas for the baseline?
Maybe everything that Java provides out of the box should be supported?
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 isObjectModel
and the DTO type isunknown
. 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 treatYear
.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