Marc Knaup
10/05/2020, 5:30 PMTing-Yuan Huang
10/05/2020, 5:54 PMMarc Knaup
10/05/2020, 6:02 PM@Json
annotations directly in the data class
. The question is if there’s a type-safe way to annotate types, properties and methods in another module and leave the data class
without annotations.
But I guess that would need some language additions. Or a fancy mix of DSL + use-site annotations.Ting-Yuan Huang
10/05/2020, 6:23 PM@AnnotatingForeignType
@Json(...)
typealias ExtStructure = Structure
Whenever the processor sees the definition in the above, it can process Structure
as if it were annotated with Json.Marc Knaup
10/05/2020, 6:24 PMZac Sweers
10/05/2020, 6:29 PMMarc Knaup
10/05/2020, 6:32 PMZac Sweers
10/06/2020, 8:38 PMMichal Harakal
10/07/2020, 2:19 PMMarc Knaup
10/07/2020, 3:10 PMMichal Harakal
10/07/2020, 3:13 PMMarc Knaup
10/07/2020, 6:09 PMdata class Duck(…)
.
Now in a different module I want to provide info about how that class is supposed to be serialized/deserialized to/from JSON.
In another module I want to provide info about how that class is supposed to represented in GraphQL.
And so on.
That info is needed at compile time so that code generation can create the code needed for serialization, GraphQL definitions instances, etc.
Annotations are great for something like that. But they’re limited to within a single module.
That means I suddenly have mix my data model (my definition of Duck) with completely unrelated information (JSON, GraphQL). The latter are an implementation detail how I use the model in various cases. So these implementation details should stay away from the data model.
Which likely means that annotations are just not the right fit for that.Michal Harakal
10/07/2020, 7:10 PMMarc Knaup
10/08/2020, 2:06 PMUser::
is annoying.
I could do the same with annotations, but not in a different module.
And there are more complex cases, like when I define a field inline,Michal Harakal
10/08/2020, 6:45 PMMarc Knaup
10/12/2020, 4:33 PMMichal Harakal
10/12/2020, 4:34 PMMarc Knaup
10/12/2020, 4:38 PMMichal Harakal
10/12/2020, 4:41 PM