pajatopmr

    pajatopmr

    1 year ago
    In the attached screen shot, I show three classes, A, B and C. A and B use interfaces and all is well. C uses a list of implementations and it passes but I would like to use a list of interfaces, as in B. When I change C to use a list of interfaces (by commenting line 48 and uncommenting line 49) the test fails with a polymorphism error message as indicated. Is there an obvious solution to this problem?
    Dominaezzz

    Dominaezzz

    1 year ago
    You need to register subclass serialisers or explicitly specify a serialiser on the interface.
    pajatopmr

    pajatopmr

    1 year ago
    @Dominaezzz can you elaborate? Perhaps show a very short example of what you think needs to change. Of point to an example with a collection of interfaces being serialized.
    Dominaezzz

    Dominaezzz

    1 year ago
    You just need a copy of line 47 in line 12.
    Just the annotation.
    pajatopmr

    pajatopmr

    1 year ago
    Line 12 is an empty line. Is that the line you meant? Like "@Serialization(...) interface A {"
    Dominaezzz

    Dominaezzz

    1 year ago
    Exactly
    pajatopmr

    pajatopmr

    1 year ago
    It works, and I thank you for that, but I'm still struggling to understand why. I did find the section on serializing interfaces and will study that for a bit.
    After studying, I noted that the fourth chapter (Polymorphism) in the section "Serializing interfaces", says: "...we cannot mark an interface itself as @Serializable." which was a big part of my confusion. But apparently we can mark an interface with "@Serializable(with = Foo::class) for example. A fine but very confusing distinction that to me is a documentation bug. Does this resonate with anyone?
    @Dominaezzz Since the documentation does not show an example that applies a serializer to an interface (based on a text search in all six chapters), I am curious how you came to know this technique if only to empower me to better utilize KXS going forward.
    Dominaezzz

    Dominaezzz

    1 year ago
    Oh. You can mark anything (except inline classes which aren't supported in general) with an explicit serializer, you can only have the plugin generate a serializer for you in specific happy cases.
    pajatopmr

    pajatopmr

    1 year ago
    And how did you come to know this ... ?
    Dominaezzz

    Dominaezzz

    1 year ago
    @Serializable
    asks the plugin to generate one. There's no reasonable way to generate a serializer for interfaces.
    Docs I guess. I've been using it for quite some time.
    They did overhaul everything recently when the library became stable, so maybe that's why.
    pajatopmr

    pajatopmr

    1 year ago
    That makes some sense ... that you've been tracking the work through many iterations. Thanks again for your insights.