Skip to content

[REQ][Kotlin][Client] Enum fallback #4621

@AlexanderEggers

Description

@AlexanderEggers

I have noticed that the current implementation of moshi does not offer an easy (generated) way to offer an enum fallback. The fallback is needed in the case if any enum gets a new parameter (via the actual api). If the server is sending back a response including this new enum value and the client does not have this new value, the related json parser will crash.

Server: MyEnum: values: MY_VALUE_A, MY_VALUE_B
Client: MyEnum: values: MY_VALUE_A

The idea would be to use the Serializer class to add new adapters. Moshi is offering a fallback enum adapter but it needs to be defined for each enum uniquely.

I would try to take care of that and offer a PR in the next days but I am not quite certain how to access the different enums in the Serializer class. The implementation would use the first value enum parameter as a fallback value.

That means the server would define a enum of:
MyEnum: values: MY_VALUE_FALLBACK, MY_VALUE_A, MY_VALUE_B

The whole implementation needs to be proper documentated and would be behind a feature flag.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions