-
Notifications
You must be signed in to change notification settings - Fork 421
feat: implement first version of sealed class serialization #1483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
O-Hannonen
wants to merge
18
commits into
google:master
Choose a base branch
from
O-Hannonen:feat/1342-implement-sealed-class-serialization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a1325b5
feat: implement first version of sealed class serialization
O-Hannonen eca56e6
fix: add assertions for sealed classes
O-Hannonen 8475a27
Fix exception name
kevmoo 77b7cf4
fix: review fixes
O-Hannonen 7e49b42
fix: fix existing tests
O-Hannonen 711cb86
feat: throw on invalid config and add support for complex sealed classes
O-Hannonen 428c276
fix: consistency improvements and more invalid config validations
O-Hannonen 8969539
test: add tests for new features
O-Hannonen 4a87046
test: add integration tests
O-Hannonen fcf2429
test: add integration tests and refine examples
O-Hannonen d7a7111
docs: bump version number and update documentation
O-Hannonen f98487b
fix: own review fixes
O-Hannonen 0aba2d3
fix: add wip suffix to json_annotation version number
O-Hannonen 839e402
fix: fix formatting for new tests
O-Hannonen e77b990
fix: fixes after rebase
O-Hannonen 6a65694
chore: update version constraint syntax
O-Hannonen 21775e4
fix: review fixes
O-Hannonen b96ed81
fix: review fixes
O-Hannonen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'complex_sealed_class_examples.g.dart'; | ||
|
||
@JsonSerializable(unionDiscriminator: 'organization') | ||
sealed class Organization { | ||
final String name; | ||
|
||
Organization({required this.name}); | ||
|
||
factory Organization.fromJson(Map<String, dynamic> json) => | ||
_$OrganizationFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$OrganizationToJson(this); | ||
} | ||
|
||
@JsonSerializable(unionDiscriminator: 'department') | ||
sealed class Department extends Organization { | ||
final String departmentHead; | ||
|
||
Department({required this.departmentHead, required super.name}); | ||
|
||
factory Department.fromJson(Map<String, dynamic> json) => | ||
_$DepartmentFromJson(json); | ||
} | ||
|
||
@JsonSerializable() | ||
class Team extends Department { | ||
final String teamLead; | ||
|
||
Team({ | ||
required this.teamLead, | ||
required super.departmentHead, | ||
required super.name, | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'sealed_class_example.g.dart'; | ||
|
||
@JsonSerializable( | ||
unionDiscriminator: 'vehicle_type', | ||
unionRename: RenameType.snake, | ||
) | ||
sealed class Vehicle { | ||
final String vehicleID; | ||
|
||
Vehicle({required this.vehicleID}); | ||
|
||
factory Vehicle.fromJson(Map<String, dynamic> json) => | ||
_$VehicleFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$VehicleToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class Car extends Vehicle { | ||
final int numberOfDoors; | ||
|
||
Car({required this.numberOfDoors, required super.vehicleID}); | ||
} | ||
|
||
@JsonSerializable() | ||
class Bicycle extends Vehicle { | ||
final bool hasBell; | ||
|
||
Bicycle({required this.hasBell, required super.vehicleID}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.