Closed Pilipets closed 3 years ago
I don't quite understand. Do you want to use banana as a serialization library? I don't think that it's good idea because banana's serializers are very stupid. Please, give an example what do you want to achieve.
Do you want to use banana as a serialization library?
In short, yes.
Details: Not purely as a serialization library, but for JSON-based serialization as well.
For example, I included banana
in my project because of telegram-communication needs, and now I want to send/process JSON for my types and other purposes - why not reuse banana::deser::serialize(...)
with custom types?
banana
already does a pretty good job with serializing/deserializing optional
, variant
, other types specified here - https://github.com/Smertig/banana/blob/master/source/serialization.hpp.
What I want is to use that compact serialization solution from the banana
for my classes and non-telegram-related purposes instead of taking another library.
I created the class, specified the serialization behavior, and now can use banana::deser::serialize(...)
and banana::deser::deserialize(...)
to get JSON strings for whatever purposes.
But if it's not expected by design, then close the issue.
JSON-serializer is not a part of public API, it's used only internally. I don't know how to allow extending serializer for user-defined types without exposing implementation details (namely, serialize_args<T>
implementation that uses <nlohmann/json.hpp>
).
The
banana
library already contains a well-structured serialization solution for telegram types - deser.hpp, meta.hpp, core.cpp and serialization.hpp, but the problem is with extensibility.If a client uses the
banana
library and needs a serialization of custom types for some other non-telegram purposes, one needs to reimplement the whole serialization/deserialization again because of thebanana
design.But what I noticed to be extremely beneficial is the ability to reuse and specify serializer behavior with custom-created types. Below I added the example of the desired functionality.
The client only creates the reflector stuff and reuses or extends(in terms of creating new
struct serializer<T>:
) logic of thebanana
library.I agree that because of the template-based serialization, it's not easy to do. However, since you referred to some upcoming changes on the JSON-related part in another issue, I'd like this one to be taken into consideration as well. P. S. I mentioned only the serialization part here for simplicity but implied deserialization as well.
Let me know your thoughts here...