mirror of https://github.com/AMT-Cheif/drift.git
Support int -> double conversion in the default serializer
This commit is contained in:
parent
48aebc0b54
commit
f9424470a5
|
@ -118,6 +118,10 @@ class _DefaultValueSerializer extends ValueSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
if (T == double && json is int) {
|
||||
return json.toDouble() as T;
|
||||
}
|
||||
|
||||
return json as T;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue