google / google/json_serializable.dart
[Feature request] compute support
- Dominant language
- Dart
- Stars
- 1.6k
- Forks
- 461
- Avg merge
- 45m
- Merged PRs (30d)
- 1
Description
**Describe the solution you'd like**
I'm using freezed in the example but in the background that is using this package.
I would like to have generated option for json serialization via isolates.
So that this:
```dart
@freezed
class DisbursementEntity with _$DisbursementEntity {
const factory DisbursementEntity({
required String asset,
required String disbursementPlatformDomain,
required String organizationName,
required String signature,
}) = _DisbursementEntity;
static Future fromJsonStringCompute(
String jsonString,
) async {
final result = await compute(
(jsonString) => DisbursementEntity.fromJson(jsonDecode(jsonString)),
jsonString,
);
return result;
}
factory DisbursementEntity.fromJson(Map json) =>
_$DisbursementEntityFromJson(json);
}
extension DisbursementEntityX on DisbursementEntity {
Future toJsonStringCompute() async {
final result = await compute(
(disbursement) => jsonEncode(disbursement.toJson()),
this,
);
return result;
}
}
```
Can become this:
```dart
@freezed
class DisbursementEntity with _$DisbursementEntity {
const factory DisbursementEntity({
required String asset,
required String disbursementPlatformDomain,
required String organizationName,
required String signature,
}) = _DisbursementEntity;
static Future fromJsonStringCompute(String json) =>
_$DisbursementEntityFromJsonStringCompute(json);
factory DisbursementEntity.fromJson(Map json) =>
_$DisbursementEntityFromJson(json);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.