rfc_3339_date_time_serializer

RFC 3339 DateTime serializer for built_value. To address the issue with datetimes with more than 6 characters in time-secfrac.


Keywords
built-value, dart, datetime, encoding
License
MIT

Documentation

rfc_3339_date_time_serializer

An RFC3339DateTimeSerializer serializer class for built_value, created to address the issue about Dart's DateTime.parse not working with RFC 3339.

Why is this package needed?

ISO 8601 has a character limit for time-secfrac part equal to 6. RFC 3339 does not have that limit. Thanks to this, datetimes introducing more than 6 characters in time-secfrac are invalid for DateTime.parse, because it works only with ISO 8601.

For example, Go's encoding/json serializes dates with 7 time-secfrac characters.

Usage

In your serializers.dart:

import 'rfc_3339_date_time_serializer/rfc_3339_date_time_serializer.dart';

@SerializersFor(const [/* (...) */])
final Serializers modelsSerializers = (_$modelsSerializers.toBuilder()
      ..addPlugin(StandardJsonPlugin())
      ..add(RFC3339DateTimeSerializer())) // this is the line you need to add
    .build();