platform/angel_serialize/lib/angel_serialize.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

2017-06-17 01:26:19 +00:00
/// Excludes a field from being excluded.
class Exclude {
2018-02-28 21:04:58 +00:00
final bool canSerialize;
final bool canDeserialize;
const Exclude({this.canDeserialize: false, this.canSerialize: false});
2017-06-17 01:26:19 +00:00
}
const Exclude exclude = const Exclude();
/// Marks a class as eligible for serialization.
class Serializable {
const Serializable(
2018-02-28 00:47:42 +00:00
{this.serializers: const [Serializers.map, Serializers.json],
this.autoSnakeCaseNames: true,
this.autoIdAndDateFields: true});
/// A list of enabled serialization modes.
///
/// See [Serializers].
final List<int> serializers;
/// Overrides the setting in `SerializerGenerator`.
final bool autoSnakeCaseNames;
/// Overrides the setting in `JsonModelGenerator`.
final bool autoIdAndDateFields;
2017-06-17 01:26:19 +00:00
}
const Serializable serializable = const Serializable();
/// The supported serialization types.
abstract class Serializers {
/// All supported serialization types.
2018-03-29 19:58:36 +00:00
static const List<int> all = const [map, json, typescript];
/// Enable `fromMap` and `toMap` methods on the model class.
2018-02-28 00:47:42 +00:00
static const int map = 0;
/// Enable a `toJson` method on the model class.
2018-02-28 00:47:42 +00:00
static const int json = 1;
2018-03-29 19:58:36 +00:00
/// Generate a TypeScript definition file (`.d.ts`) for use on the client-side.
static const int typescript = 2;
}
2017-06-17 01:26:19 +00:00
/// Specifies an alias for a field within its JSON representation.
class Alias {
final String name;
2017-06-17 01:26:19 +00:00
const Alias(this.name);
}