{% hint style="warning" %} Experimental {% endhint %}
Chopper converter for built_value serializer.
# pubspec.yaml
dependencies:
chopper_build_value: ^0.0.1
Define your models.
abstract class DataModel implements Built<DataModel, DataModelBuilder> {
int get id;
String get name;
static Serializer<DataModel> get serializer => _$dataModelSerializer;
factory DataModel([updates(DataModelBuilder b)]) = _$DataModel;
DataModel._();
}
Aggregate all serializers
/// Collection of generated serializers for the built_value
@SerializersFor([
DataModel,
])
final Serializers serializers = _$serializers;
See built_value documentation for more informations.
Provide serializers to the converter and to the ChopperClient.
final builder = serializers.toBuilder();
builder.addPlugin(StandardJsonPlugin());
final jsonSerializers = builder.build();
final converter = BuiltValueConverter(jsonSerializers);
final client = ChopperClient(converter: converter);
You can use BuiltValueConverter
as an error converter. It will try to decode error using the wireName
inside JSON {"$":"ErrorModel"}
if available.
If wireName
is not available, you can specify the type of your error to the converter.
BuiltValueConverter(jsonSerializers, errorType: ErrorModel);