Skip to content

Simplify mapping iterables in toData and fromData implementations of common domain model classes #12

@ghost

Description

See sample domain model classes with JSON serialization

On this sample PersonCollection is defined as:

class PersonCollection {
  final Iterable<Person> persons;

  const PersonCollection({required this.persons});

  factory PersonCollection.fromData(DataArray data) => PersonCollection(
        persons: data.objects
            .map((element) => Person.fromData(element))
            .toList(growable: false),
      );

  DataArray toData() => DataArray.of(
        persons.map((person) => person.toData()).toList(growable: false),
      );
}

Mapping iterables in both directions in fromData and toData could be easier to implement?

Find choices and add support on DataObject and/or DataArray.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🗒️ attributesRelated to the code package "attributes"enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions