dart-dio.local_date_serializer.mustache Maven / Gradle / Ivy
{{>header}}
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:time_machine/time_machine.dart';
class OffsetDateSerializer implements PrimitiveSerializer {
const OffsetDateSerializer();
@override
Iterable get types => BuiltList([OffsetDate]);
@override
String get wireName => 'OffsetDate';
@override
OffsetDate deserialize(Serializers serializers, Object serialized,
{FullType specifiedType = FullType.unspecified}) {
final local = LocalDate.dateTime(DateTime.parse(serialized as String));
return OffsetDate(local, Offset(0));
}
@override
Object serialize(Serializers serializers, OffsetDate offsetDate,
{FullType specifiedType = FullType.unspecified}) {
return offsetDate.toString('yyyy-MM-dd');
}
}
class OffsetDateTimeSerializer implements PrimitiveSerializer {
const OffsetDateTimeSerializer();
@override
Iterable get types => BuiltList([OffsetDateTime]);
@override
String get wireName => 'OffsetDateTime';
@override
OffsetDateTime deserialize(Serializers serializers, Object serialized,
{FullType specifiedType = FullType.unspecified}) {
final local = LocalDateTime.dateTime(DateTime.parse(serialized as String));
return OffsetDateTime(local, Offset(0));
}
@override
Object serialize(Serializers serializers, OffsetDateTime offsetDateTime,
{FullType specifiedType = FullType.unspecified}) {
return offsetDateTime.toString();
}
}