Skip to content

Commit

Permalink
feat(thing_description.dart): add basic toJson implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed May 18, 2024
1 parent 3c1235f commit 55ce372
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 7 additions & 4 deletions lib/src/core/definitions/thing_description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ThingDescription {
required this.title,
required this.security,
required this.securityDefinitions,
required Map<String, dynamic> rawThingDescription,
this.titles,
this.atType,
this.id,
Expand All @@ -51,7 +52,7 @@ class ThingDescription {
this.version,
this.uriVariables,
this.prefixMapping,
});
}) : _rawThingDescription = rawThingDescription;

/// Creates a [ThingDescription] from a [json] object.
Expand Down Expand Up @@ -136,6 +137,7 @@ class ThingDescription {
security: security,
securityDefinitions: securityDefinitions,
atType: atType,
rawThingDescription: json,
);
}

Expand All @@ -146,9 +148,10 @@ class ThingDescription {
}

/// Converts this [ThingDescription] to a [Map] resembling a JSON objct.
Map<String, dynamic> toJson() {
throw UnimplementedError();
}
// TODO: Revisit this for dynamic serialization
Map<String, dynamic> toJson() => _rawThingDescription;

final Map<String, dynamic> _rawThingDescription;

/// Contains the values of the @context for CURIE expansion.
final PrefixMapping? prefixMapping;
Expand Down
6 changes: 1 addition & 5 deletions test/core/thing_description_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ void main() {
};
final thingDescription = thingDescriptionJson.toThingDescription();

// TODO(JKRhb): Implement toJson method
expect(
thingDescription.toJson,
throwsUnimplementedError,
);
expect(thingDescriptionJson, thingDescription.toJson());
});

test("should throw a ValidationException when it is invalid during parsing",
Expand Down

0 comments on commit 55ce372

Please sign in to comment.