Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic SerializationCustomSerializer #6887

Open
manosbatsis opened this issue Mar 12, 2021 · 1 comment
Open

Support generic SerializationCustomSerializer #6887

manosbatsis opened this issue Mar 12, 2021 · 1 comment
Assignees
Labels

Comments

@manosbatsis
Copy link
Contributor

Currently implementations of SerializationCustomSerializer need to be specific about the target type, so i end up with e.g.

class AppleSerializer(): FruitCustomSerializer<Apple>(),
        SerializationCustomSerializer<Apple, JsonStringProxy<Apple>>
class OrangeSerializer(): FruitCustomSerializer<Orange>(),
        SerializationCustomSerializer<Orange, JsonStringProxy<Orange>>
// repeat for all fruit types

Instead, i would like to create a generic serializer or factory like

class FruitCustomSerializer<T: Fruit> : SerializationCustomSerializer<T, JsonStringProxy<T>> {
   

    override fun toProxy(obj: T): JsonStringProxy<T> {
        return JsonStringProxy(
                jsonString = FruitUtil.toJsonString(obj),
                targetType = obj.javaClass)
    }

    override fun fromProxy(proxy: JsonStringProxy<T>) : T {
        return FruitUtil.toFruit(proxy.jsonString, proxy.targetType)
    }

}

I suppose the API could be enhanced with a method for the serializer to report if it supports a concrete class etc.

@nargas-ritu
Copy link
Contributor

Created CORDA-4191 for an internal review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants