Skip to content

Serializing certain types as String #2

@tombentley

Description

@tombentley

A good example is Date: I don't want to serialize this as a Json hask with a bunch of integer values, I want to serialize is as an ISO-8601 date.

Conceptually I could do that by supporting pluggable formatters & parsers. The problems come (in the Serializer) when I want to invoke a formatter (in val()):

  1. Basically val() gets called a lot, and this idea relies on being able to look up a user supplied formatter from an instance quickly. But that lookup involves instance→ type →multiple map lookups for inheritance. I don't really want to put that on a hot path.
  2. Worse, I can't even make it work because in val() I have a (static type) Object, it has runtime type T and although I can lookup a Formatter<T> there's no way to invent a static type to represent the runtime type, so even though the invocation is safe, the typechecker can't see that. I need Reified/Runtime Type Aliases eclipse-archived/ceylon#4465 to solve that efficiently. In the meantime I'm left with the metamodel, which is going to be really slow.

Note to self: This is partially implemented in the string-serializer branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions