diff --git a/lib/src/core/definitions/form.dart b/lib/src/core/definitions/form.dart index bd514d4c..425cc8e5 100644 --- a/lib/src/core/definitions/form.dart +++ b/lib/src/core/definitions/form.dart @@ -21,7 +21,7 @@ class Form implements Serializable { /// An [href] has to be provided. A [contentType] is optional. Form( this.href, { - this.contentType = "application/json", + this.contentType = _defaultContentType, this.contentCoding, this.subprotocol, this.security, @@ -86,6 +86,8 @@ class Form implements Serializable { ); } + static const _defaultContentType = "application/json"; + /// The [href] pointing to the resource. /// /// Can be a relative or absolute URI. @@ -134,7 +136,6 @@ class Form implements Serializable { Map toJson() { final result = { "href": href.toString(), - "contentType": contentType, ...additionalFields, }; @@ -148,6 +149,10 @@ class Form implements Serializable { op.map((opValue) => opValue.toString()).toList(growable: false); } + if (contentType != _defaultContentType) { + result["contentType"] = contentType; + } + if (contentCoding != null) { result["contentCoding"] = contentCoding; } diff --git a/test/core/definitions/serialization_test.dart b/test/core/definitions/serialization_test.dart index 0a7e7f4e..74615d13 100644 --- a/test/core/definitions/serialization_test.dart +++ b/test/core/definitions/serialization_test.dart @@ -38,8 +38,6 @@ void main() { "op": [ "readmultipleproperties", ], - // TODO: Should defaults actually be set? - "contentType": "application/json", }, ], "properties": {}, @@ -103,7 +101,6 @@ void main() { "href": "https://example.org", "subprotocol": "foobar", "contentCoding": "test", - "contentType": "application/json", "security": ["test"], "response": { "contentType": "application/json", @@ -123,7 +120,6 @@ void main() { test("AugmentedForms", () async { final formJson = { "href": "https://example.org", - "contentType": "application/json", }; final thingDescription = { @@ -186,7 +182,6 @@ void main() { "forms": [ { "href": "https://example.org", - "contentType": "application/json", } ], };