celest
celest copied to clipboard
Add Serializers to the documentation, so that it's part of the public API
I think it's very important that we're able to access Celest's serialization for other purposes:
- It's very useful, why not?
- If we have access to it, you make it testable.
- Third, making it accessible will help when we need to migrate when the model evolves.
- If you don't, you force me to use other serialization techniques, which is duplicating not only the code, but may result in different serializations, which complicates things for no reason.
So, basically, explain that this is possible:
Object? toJsonPersistor() => Serializers.instance.serialize<AvailableStock>(this);
factory AvailableStock.fromJsonPersistor(Object? value) =>
Serializers.instance.deserialize<AvailableStock>(value);
Note: Maybe make it a bit simpler, but defining two extra static methods, serialize and deserialize:
static Object? serialize<T>(T value) => instance.serialize(value);
static T deserialize<T>(Object? value) => instance.deserialize(value);
So that we can write:
Object? toJsonPersistor() => Serializers.serialize<AvailableStock>(this);
factory AvailableStock.fromJsonPersistor(Object? value) => Serializers.deserialize<AvailableStock>(value);
That way, Celest users don't have to use instance, and we don't make instance part of the public API. But feel free to ignore these if you don't think it's a good idea.
Thanks, Marcelo!