Skip to content

Add support for additional dart:core types #1784

Open

Description

@Isakdl

Add support for additional dart core types in our serialization and model files

Activity

  1. added
    enhancement
    on Jan 19, 2024
  2. moved this to Version 2.0 - Nice to have 🥳 in Serverpod Frameworkson Feb 5, 2024
  3. vlidholt commented on Feb 5, 2024

    @vlidholt
    Collaborator

    Iterable is more or less covered by List, no?

  4. Isakdl commented on Feb 6, 2024

    @Isakdl
    CollaboratorAuthor

    Not necessarily, I mean the serialized version would still probably be a list, but an iterator can be much more than just a list. It could add value to be able to use an iterator on the class rather than a list and it shouldn't be too hard to implement.

    In any case the above types are the ones we do not support that the Google maintained package: https://pub.dev/packages/json_serializable supports.

  5. added
    area: models
    area: endpoints
    and removed
    enhancement
    on Dec 19, 2024
  6. moved this from Later 🥳 to Next 🌟 in Serverpod Frameworkson Jan 13, 2025
  7. SandPod commented on Jan 15, 2025

    @SandPod
    Contributor

    Working method:
    In separate PRs for each type, first, add it so that it can be sent and received from an endpoint. After that, we can consider adding support for it in the model definition. But this will be a case-by-case decision.

  8. Isakdl commented on Jan 15, 2025

    @Isakdl
    CollaboratorAuthor

    @SandPod Database support also needs to be considered even if they just map to an existing database type.

  9. moved this from Next 🌟 to Now 🔥 in Serverpod Frameworkson Jan 27, 2025
  10. assigned and unassigned on Jan 28, 2025
  11. tp commented on Feb 3, 2025

    @tp
    Contributor

    A few questions / comments about the remaining types to be implemented.

    Iterable

    What would be the expectations of when to read the iterator? Personally I would've started out with consuming the iterator once when creating the model class. That means it would only ever be consumed once (per model class), and internally (to the model class and database) it could just behave like a List<T>.

    We could of course also retain the Iterable itself on the model class, but then we might get different values at different points (depending on how it/what is implemented), or succeed once and fail another time (e.g. when saving it to the database vs. sending the seemingly "same" model to the client afterwards).

    num

    Would you go for double precision in the database here, or some more specific type like decimal with a higher precision, such that we could best map all possible numeric Dart types?

    How important would it be to retain the original "source" type when round-tripping under the hood? I wonder if a 3.0 (double) might not become a 3 (int). But maybe that would be fine, as people who opted into this more flexible type will just be OK treating it as 3 (num) all the time.

    Record

    This should be fine overall, I'll just have to dig into how we handle the case when the framework things "the type of this field has changed".

    I think we would need to be a lot more flexible at that stage then, to e.g. allow additions of null positional and/or named parameters.

    E.g. going from ({int id, String name}) to ``({int id, String name, String? phone})` should be allowed in my opinion.

    Set

    (Ordered) Sets seem like a good type for relations, but initially I left it out, as the creation case seems tricky given that we don't have object equality on the models. Once we have an ID from the database, we could ensure that an item is present no more than once. But this would probably become quite a big undertaking overall.

  12. added a commit that references this issue on Feb 7, 2025
  13. SandPod commented on Feb 11, 2025

    @SandPod
    Contributor

    A couple of responses to the questions above.

    Iterable

    I don't think we should resolve the iterable to a list. If the developer wants that behavior it would be perfectly fine to use a list as a type instead and resolve any iterable before assigning. I believe the use-case here is specifically to have the flexibility an iterable brings, with the risk of having inconsistent behavior.

    Num

    Couldn't we store it as a string and encode it with type? That would allow us to always restore the type that was actually saved in the field. And since the developer has specified num instead of a specific type, I would expect them to be fine with the potential performance when serializing/deserializing.

  14. tp commented on Feb 17, 2025

    @tp
    Contributor

    I don't think we should resolve the iterable to a list.

    @SandPod Suppose we have an Iterable<T> on the model, I agree that we could keep this around as long as the model is alive. But when creating the same model from the database or receiving it from the network, I think it'd have to backed by a List<T> as we don't know what other type the user would want to use.

    In any case I would probably defer this until someone comes up with a practical example that would benefit from this, as personally I think we're well covered with Set & List (incl. the ability that one can switch between them (at least if they don't contain any duplicates)).

    Couldn't we store it as a string and encode it with type?

    That sounds feasible. We'd just have to look into whether we can retain any of the database filter operations. That is also still outstanding for BigInt (serialized as string) where you currently can not sort/filter numerically.

  15. SandPod commented on Feb 18, 2025

    @SandPod
    Contributor

    Noting down some decisions from a discussion between @tp and me.

    • We will support Iterable with specific types in the model. We believe the biggest usecase for this, as opposed to using a Set or List is that developers would like to assign generators to their models on the server or client side.
    • These generators should be resolved uniquely for each serialization; this allows the result of a generator to be easily passed through serialization.
    • When consistent result is desired, a Set or List should be used instead.
  16. moved this from Now 🔥 to Next 🌟 in Serverpod Frameworkson Jun 12, 2025
  17. moved this from Next 🌟 to Later 🥳 in Serverpod Frameworkson Jun 12, 2025
  18. moved this from Later 🥳 to Backlog 🗂️ in Serverpod Frameworkson Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: endpointsarea: models

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions