How to handle nullable values in custom TypeAdapter
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
How should a customer adapter handle potential null attribute values? I.e. I want to persist the null values when they are null:
**Code sample**
```dart
class MyObjectAdapter extends TypeAdapter {
@override
MyObject read(BinaryReader reader) {
return MyObject(
someIntAttribute: reader.readInt(), // <-- might be null but what bytes would actually be stored to represent null?
}
@override
int get typeId => 1;
@override
void write(BinaryWriter writer, MyObject obj) {
writer.writeInt(obj.someIntAttribute); // want to write something to represent null when someIntAttribute happens to be null
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the TypeAdapter implementation shown in the issue and inspect the BinaryReader and BinaryWriter APIs used by readInt and writeInt. Confirm how nullable values are represented by these entry points, then document the supported approach and update any relevant usage guidance if the repository identifies a documentation location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- database
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100