tombentley / alabama

A JSON-based Ceylon serialization library
Other
6 stars 2 forks source link

Serializing certain types as String #2

Open tombentley opened 7 years ago

tombentley commented 7 years ago

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 ceylon/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.