-
Notifications
You must be signed in to change notification settings - Fork 0
Classes
Define Dart classes that you want to serialize or deserialize. Annotate these classes with the necessary annotations from the generated file from the object
package to specify serialization behavior.
sample.dart
inmodel/
folder
import 'generated/model.g.dart';
class Sample extends SampleGen {
@override
@Field(
name: 'id',
primary: true,
)
String id = '';
@override
@Field(name: 'numberContent')
num numberContent = 0;
Sample();
}
Run the object builder to generate serialization code for your annotated Dart classes.
dart run object:build
The @Field
annotation lets you easily de/serialize Dart instances. It offers different parameters:
@Field(
name: 'some_key',
)
The key for de/serialization.
@Field(
primary: true,
)
Sets the current field as the primary key to differentiate that instance from others.
@Field(
basic: true,
)
Sets if the current field should have a basic de/serialization.
toJson()
'field': instance['field']
fromJson()
instance['field'] = json['field']
@Field(
recycle: true,
)
Defines the current field for being recycled on the deserialization process. Instead of creating a new instance of the field, the library will use the old one, to avoid memory consumption.
This field only applies to complex instances, not to primitive types.
@Field(
import: 'package:my_app_package/model/other_class.dart',
)
Helps de/serialize instances whose classes are not managed by the library.
@Field(
defaultValue: DefaultValue(
value: 3 | true | 'string',
),
)