Support int -> double conversion in the default serializer

This commit is contained in:
Simon Binder 2020-01-31 10:28:01 +01:00
parent 48aebc0b54
commit f9424470a5
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 14 additions and 0 deletions

View File

@ -118,6 +118,10 @@ class _DefaultValueSerializer extends ValueSerializer {
}
}
if (T == double && json is int) {
return json.toDouble() as T;
}
return json as T;
}

View File

@ -18,6 +18,16 @@ void main() {
expect(deserialized, equals(deserialized));
});
test('can deserialize ints as doubles', () {
final entry = TableWithoutPKData.fromJson({
'notReallyAnId': 3,
'someFloat': 4,
});
expect(entry,
TableWithoutPKData(notReallyAnId: 3, someFloat: 4, custom: null));
});
test('default serializer can be overridden globally', () {
final old = moorRuntimeOptions.defaultSerializer;
moorRuntimeOptions.defaultSerializer = _MySerializer();