serialize method

  1. @override
Object serialize(
  1. Serializers serializers,
  2. Rational object, {
  3. FullType specifiedType = FullType.unspecified,
})
override

Serializes object.

Use serializers as needed for nested serialization. Information about the type being serialized is provided in specifiedType.

Returns a value that can be represented as a JSON primitive: a boolean, an integer, a double, a String or a List.

TODO(davidmorgan): document the wire format.

Implementation

@override
Object serialize(Serializers serializers, Rational object,
    {FullType specifiedType = FullType.unspecified}) {
  final str = object.toDouble().toString();
  final splitted = str.split('.');
  final whole = splitted[0];
  final decimal = splitted[1];
  final fineDecimal = decimal.padRight(fractionDigits, '0').substring(0, fractionDigits);
  return '$whole$fineDecimal';
}