diff --git a/lib/src/core/definitions/interaction_affordances/property.dart b/lib/src/core/definitions/interaction_affordances/property.dart index 39bde37a..b678b153 100644 --- a/lib/src/core/definitions/interaction_affordances/property.dart +++ b/lib/src/core/definitions/interaction_affordances/property.dart @@ -15,7 +15,7 @@ class Property extends InteractionAffordance implements DataSchema { super.uriVariables, super.additionalFields, required this.dataSchema, - this.observable = false, + this.observable = _defaultObservableValue, }); /// Creates a new [Property] from a [json] object. @@ -51,6 +51,22 @@ class Property extends InteractionAffordance implements DataSchema { return property; } + @override + Map toJson() { + final result = { + ...super.toJson(), + ...dataSchema.toJson(), + }; + + if (observable != _defaultObservableValue) { + result["observable"] = observable; + } + + return result; + } + + static const _defaultObservableValue = false; + /// The internal [DataSchema] this property is based on. final DataSchema dataSchema; @@ -148,8 +164,15 @@ class Property extends InteractionAffordance implements DataSchema { @override Map get additionalFields { - final additionalDataSchemaFields = dataSchema.additionalFields.entries - .where((entry) => super.additionalFields.containsKey(entry.key)); + final additionalDataSchemaFields = + dataSchema.additionalFields.entries.where( + (entry) => [ + ...super.additionalFields.keys, + "observable", + ].contains( + entry.key, + ), + ); return Map.fromEntries(additionalDataSchemaFields); }