JSON - howto serialise enumerations?

When serialising openEHR types to JSON should we use the numbered code or the name of the type?

I.e. when serialising VALIDITY_KIND enumeration

I know we discussed this sometime ago, but I wasn’t able to find the resource.

I’m not sure what you refer as “numbered code”.

Depending on what you refer, if you need to serialize and attribute that has this type, and if it is the old values from RM 1.0.2, where in XSD was:

<xs:simpleType name=“VALIDITY_KIND”>
<xs:restriction base=“xs:integer”>
<xs:enumeration value=“1001” id=“mandatory”/>
<xs:enumeration value=“1002” id=“optional”/>
<xs:enumeration value=“1003” id=“disallowed”/>
</xs:restriction>
</xs:simpleType>

is indeed more tricky to think of what should be in the JSON, but nowadays (BASE Release-1.1), this type contains only string values, so it is easier - just refer to the value.

When you need to serialize the type definition, you just have to include the name; if on the other hand you need something like the values from enumeration, I assume you will need the JSON-schema of this type, and that should contain the enumeration itself.

Does this answer your question?

1 Like