-
Notifications
You must be signed in to change notification settings - Fork 4
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
Custom primitive types / built-in types #156
Comments
I think the |
Could we help in some way to get this feature in quicker? |
In many unrealistic and impractical ways... Are you working on a concrete use case implementation that needs this? |
Yes, our ASTs have source position information objects that used to be represented as nodes in Lionweb but that would be too much for the model repository to handle for some larger ASTs. So we switched to representing them as attributes. However, now we cannot deserialize those models in our web application anymore, and as far as I know we cannot work around it (except by reimplementing the import from JSON). |
(btw: I think here you should be using the key instead of the ID.) |
I think the mechanism of registering serializers (and possibly deserializers) for specific primitive types (identified by meta-pointer should not be very difficult to add to the TS implementation as well, and its implementation would have much interference from the re-architecting, so I might try and make some time to have a stab at it this week(-ish). Keep bugging me to ensure ;) |
I have added an issue to track that: LionWeb-io/lionweb-java#141 |
According to LionWeb-io/specification#10, we don't support custom primitive types yet. |
Good point! Having support in the main two implementations might give the wrong idea, even. On the other hand: people can define their own primitive types in their languages (and we didn't curb that capability as per LionWeb-io/specification#10). I wouldn't mind at least improving the (de-)serialization of values of properties having a primitive type a bit (because it's a bit...happenstance, right now), and then some kind of parametrization is also easier. |
My understanding is that ultimately every primitive value ends up being serialized as a string into a "LW JSON file". The indication of the primitive type just tells us how to interpret that string. For example, "10" may be become 10, if the primitive type is int, while it could stay "10", if the type is a string. Suppose someone wants to use LocalDates. If they use JSON to represent that, it means that values will be unserialized as JSON (for example, instances of JSONElement in Java). That would be way less convenient that having instances of LocalDates, for example. Basically all operations will require to convert back and forth between LocalDate and JSONElement, to ultimately store JSONElements values in the node.
This means that we can define primitive types, but if we use them, serialization/deserialization should fail. |
To me, there's one main advantage of our JSON primitive type: As a user (i.e. developer using e.g. Java), I'd get it as Looking at LocalDate, the story is different. Most programming languages already have some way of representing it. If we wanted interoperability, we had to come up with a language definition to represent the underlying data, and a "gentlemen's agreement" that every host language would have special handling of that language to represent it in the proper way for the host language. I read LionWeb-io/specification#10 as postponed, i.e. not decided yet (yes, the text is a bit ambiguous). I'm not sure to what extent custom datatypes are supported in all implementations (C# doesn't support it atm). |
Indeed we are using a custom primitive type to represent the Position of an AST node in a file (as a pair of Line and Column). We want to do that because the class Position has many convenient methods. Let's say we have nodes with positions expressed through a specific class:
If I want to check if one node comes before another one, I can do that easily:
If I represent it as JSONElement:
I need to do the conversion from JSONElement to position before invoking the operation. Also, I have code that is more error prone as certain JSONElements could be converted to positions, while others would be representing other things. Without custom primitive types, it seems to be that:
Also, this is asymmetric to what we do for node classes: for node classes, we can specify specific classes to be instantiated when unserializing nodes. It would be useful to have the same approach for primitive types.
Yes, but it sort of "partially unserialize" because it goes from String to JSONElement, but not to the final data types that would make the processing convenient (e.g., instances of the class Position). |
I agree completely --> LionWeb-io/specification#265 |
I think some wiggle room exists between fully supporting custom primitive types (e.g., guaranteed and specified plugin points in the [de-]serializer in our own reference implementations) and fully forbidding custom primitive types (in which case the only instances of Currently, I feel that we should align our stance on custom primitive types, and maybe clarify that (FAQ-style?). |
I see in
deserializeBuiltin
there is no way to deserialize a custom type while Lionweb/Java supports this (https://github.com/LionWeb-io/lionweb-java/blob/8b7bb5d9dee3f9687ea6847c72afb1aea85847b1/core/src/main/java/io/lionweb/lioncore/java/serialization/PrimitiveValuesSerialization.java#L56-L60).We now have encountered models serialized with that feature from Java that we cannot deserialize in JS.
Is this planned? Is there a workaround?
The text was updated successfully, but these errors were encountered: