LionWeb-io / lionweb-java

Apache License 2.0
3 stars 1 forks source link

Representing enumeration values #137

Closed ftomassetti closed 6 months ago

ftomassetti commented 6 months ago

When a property is of type enumeration, we had not a clear expectation on how the value should be represented. In different places we were expecting:

With this PR we define the interface EnumerationValue (and the class EnumerationValueImpl, previously called DynamicEnumerationValue). The standard approach should be to use this to represent enumeration value. This will make it clear that we are not representing just a string or the definition a new enumeration literal but representing an instance of an enumeration corresponding to a certain literal.

Users can still decide to represent enumeration values in other ways, if they wish so, but in that case they would need to provide primitive serializers and deserializers. If they instead use the EnumerationValue serialization and deserialization will work out of the box.

enikao commented 6 months ago

Do we still have tests that use actual java enums?

ftomassetti commented 6 months ago

Do we still have tests that use actual java enums?

I am not sure if we ever had such tests. However this comment gives me the idea that we may have support for using enum values to represent values of properties of Enumeration type. In that case, if we had an enum instance we would not not from that to which Enumeration and EnumerationLiteral it would be connected. However, knowing the property to which it is assigned we could get the Enumeration from there and then look at the EnumerationLiteral with the same name as the enum instance. Do you think it would make sense to add support for that as part of this PR?

enikao commented 6 months ago

Do you think it would make sense to add support for that as part of this PR?

Yes, as this PR claims to bring the flexibility to do both. Then we should also test it.

ftomassetti commented 6 months ago

Yes, as this PR claims to bring the flexibility to do both. Then we should also test it.

This is not what I meant initially, but I think it is a good idea so I added support for using Enum instances to represent instances of EnumerationLiteral and added some tests for serialization and deserialization of such values