is there any examples using @Implements with json_serializable ? #971
-
Here is the code let me confuse. import 'package:freezed_annotation/freezed_annotation.dart';
part 'example.freezed.dart';
part 'example.g.dart';
abstract class GeographicArea {
int get population;
String get name;
String get area;
}
@freezed
sealed class Example with _$Example {
const factory Example.person(
@JsonKey(name: 'name') String name, @JsonKey(name: 'age') int? age) =
Person;
factory Example.fromJson(Map<String, Object?> json) =>
_$ExampleFromJson(json);
@Implements<GeographicArea>()
const factory Example.city(String name, int population) = City;
}
test() {
// is this correct?
City a = City.fromJson({
'name': 'John Smith',
'age': 42,
});
} |
Beta Was this translation helpful? Give feedback.
Answered by
rrousselGit
Aug 31, 2023
Replies: 1 comment 3 replies
-
I don't understand what this is about. Could you be more specific? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure that should work.