Open dglachs opened 2 years ago
Hi @dglachs , first of all, really sorry for not answering earlier. It looks like I completely lost track of this issue.
According to the proposed content: Looks great! I'll prepare a feature branch soon and check how it works with the current state of the generator and the V3.0 AAS metamodel version.
(And, by the way, pretty impressive that you were able to go through the templates just by yourself!)
Hello all,
this is a proposal for improvement ...
currently, the generation of enums simply transforms the name of the class name to a SCREAMING_SNAKE_CASE notation. During de/serialization an extra Serializer/Deserializer has to take care of again transforming the SCREAMING_SNAKE_CASE into the serialization value (CamelCase), e.g.
ASSET_ADMINISTRATION_SHELL --> AssetAdministrationShell SUBMODEL --> Submodel SUBMODEL_ELEMENT --> SubmodelElement
this works well, when the transformation is always according to this transformation rule. However, this approach has several drawbacks:
module.addSerializer(Enum.class, new EnumSerializer());
cannot be used with a ObjectMapper for example with SpringBoot.To simplify the use of enums with the AAS Model, i'd propose to keep the "serialized" value of the enumeraton such as
ASSET_ADMINISTRATION_SHELL("AssetAministrationShell") in KeyTypes or ANY_URI("xs:anyURI") in DataTypeDefXsd
This can be achieved by changing few templates:
and by adding a new template
all of the files are attached!
changes to the distinct files are as follows:
enum-default-methods.rq
Simply generate a constructor, override the toString() method and add a static "fromValue(String text)" method. Optionally (?useJackson) add the required JsonAnnotations for @JsonValue and @JsonCreator (adopt basic-imports.rq)!
enum-default-properties.rq
add the member variable "value".
process-enum-individuals.rq
use the constructor and add the value, here the template providing the enum's value is called!
to_enum_value.rq
This template checks whether the parent is DataTypeDefXsd and constructs the respective name, taking into account that the definition is named AnyUri (not AnyURI) and the first character is lowercase ... in all other cases, the name of the class is used.
Mixin instead of EnumSerializer/EnumDeserializer
using a mixin-class for each of the enums does the job. As a result, the EnumSerializer or Deserializer can be omitted
AASEnumGeneration.zip