-
Notifications
You must be signed in to change notification settings - Fork 57
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 @JsonCreator and @JsonValue when generating TypeScript from Java #2055
Comments
Hilla generator does not distinguish input and output types. So we need to provide support for both at the same time. Let's take |
1 similar comment
Hilla generator does not distinguish input and output types. So we need to provide support for both at the same time. Let's take |
I don't know how feasible it is at code level, but would it be reasonable to automatically unpack all single-property objects when dealing with TS? That would mean that I think that it would be a nice way to simplify developers' life with those types. The main drawback is that, if the object becomes |
Automatic handling of single-property objects might make sense but I suspect we would still also need to support |
In both cases, there are some further aspects that must be taken into account. One is different nullability between types. For example, if a Generics must be taken into account too: suppose we have a |
Describe your motivation
In Java, it is a good practice to use domain primitives rather than ordinary primitives in certain situations. For instance, instead of using a
String
orlong
as the customer ID, you should create aCustomerId
type that wraps aString
orlong
. It should be possible to use domain primitives like this in@BrowserCallable
services.Describe the solution you'd like
Although having domain primitives in TypeScript would be nice, it isn't as important as having them in Java. I would be fine with a solution where I can use domain primitives in Java and basic types in TypeScript. The easiest way to do this would be to support
@JsonValue
and@JsonCreator
on the Java side.My
CustomerId
class would have a method (maybetoString()
) annotated with@JsonValue
. An outgoingCustomerId
object would then be serialized to astring
in TypeScript.I would also have a corresponding constructor that accepts a single
String
parameters and is annotated with@JsonCreator
. An incoming TypeScriptstring
would then be deserialized to aCustomerId
object.Describe alternatives you've considered
I could make separate
@BrowserCallable
services and DTOs that use ordinary primitives and do the conversion manually on the Java side before delegating to the "real" services and DTOs that use domain primitives. However, this feels like unnecessary complexity if the only difference between these services and DTOs is that the domain primitives have been replaced with their wrapped ordinary primitives.Additional context
No response
The text was updated successfully, but these errors were encountered: