google / google/built_value.dart

[Question] Returning or NOT Returning a nullable from deserializeWith ?

Open
#1,168 1 comment 0 reactions 1 assignee Claimed by @davidmorgan View on GitHub
question
Dominant language
Dart
Stars
886
Forks
195
Avg merge
1d 11h
Merged PRs (30d)
4

Description

My code is implementing a fromJson method calling the **deserializeWith** method returning an optional.

- Is it safe for me to return a Beacon and not a Beacon? ?

- In which case a null will be returned from the **deserializeWith** method

Code would be simple to maintain if method is returning a non nullable value and throw exception when required

```
static Beacon? fromJson(String jsonString) {
return serializers.deserializeWith(
Beacon.serializer, json.decode(jsonString));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.