Skip to content

Commit

Permalink
fix(dynamite_runtime): contentstring serialize null values
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Dec 13, 2023
1 parent 39255db commit 615310f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class ContentStringPlugin implements SerializerPlugin {
return object;
}

if (object == null) {
return object;
}

if (object is! Map<String, dynamic>) {
throw StateError('ContentStringPlugin can only be applied to Map<String, dynamic>. '
'Please ensure the StandardJsonPlugin is applied and run before.');
Expand All @@ -37,6 +41,10 @@ class ContentStringPlugin implements SerializerPlugin {
return object;
}

if (object == null) {
return object;
}

if (object is! String) {
throw StateError('The serialized ContentString must be of type String. '
'Please ensure the StandardJsonPlugin is applied and run before.');
Expand Down
14 changes: 14 additions & 0 deletions packages/dynamite/dynamite_runtime/test/content_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,18 @@ void main() {
);
});
});

group('Serialize null value', () {
const data = null;
const serialized = null;
const specifiedType = FullType(ContentString, [FullType(bool)]);

test('can be serialized', () {
expect(serializers.serialize(data, specifiedType: specifiedType), serialized);
});

test('can be deserialized', () {
expect(serializers.deserialize(serialized, specifiedType: specifiedType), data);
});
});
}

0 comments on commit 615310f

Please sign in to comment.