Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dynamite_runtime): contentstring serialize null values #1283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
}