Skip to content

Commit

Permalink
fixup! feat!: implement proper serialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jun 3, 2024
1 parent 7433ef3 commit 321de01
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/core/definitions/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ class Form {

/// Additional fields collected during the parsing of a JSON object.
final Map<String, dynamic> additionalFields = {};

Map<String, dynamic> toJson() {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ sealed class InteractionAffordance {

/// Additional fields that could not be deserialized as class members.
final Map<String, dynamic>? additionalFields;

Map<String, dynamic> toJson() {
throw UnimplementedError();
}
}
48 changes: 48 additions & 0 deletions lib/src/core/definitions/thing_description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,54 @@ class ThingDescription {
result["description"] = description;
}

final version = this.version;
if (version != null) {
result["version"] = version.toJson();
}

if (created != null) {
result["created"] = created.toString();
}

if (modified != null) {
result["modified"] = modified.toString();
}

if (support != null) {
result["support"] = support.toString();
}

if (base != null) {
result["base"] = base.toString();
}

if (id != null) {
result["id"] = id;
}

final forms = this.forms;
if (forms != null) {
result["forms"] = forms.map((form) => form.toJson());
}

final properties = this.properties;
if (properties != null) {
result["properties"] =
properties.map((key, property) => MapEntry(key, property.toJson()));
}

final actions = this.actions;
if (actions != null) {
result["actions"] =
actions.map((key, action) => MapEntry(key, action.toJson()));
}

final events = this.events;
if (events != null) {
result["events"] =
events.map((key, event) => MapEntry(key, event.toJson()));
}

return result;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/src/core/definitions/version_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class VersionInfo {

/// Additional fields collected during the parsing of a JSON object.
final Map<String, dynamic>? additionalFields;

/// Converts this [VersionInfo] to a [Map] resembling a JSON object.
Map<String, dynamic> toJson() {
throw UnimplementedError();
}
}

0 comments on commit 321de01

Please sign in to comment.