如果 Moshi 中的值不匹配,如何回退到枚举

How to fallback on a enum if values don't match in Moshi

我有一个枚举 class,如果值与其中任何一个都不匹配,我希望它回退到特定的枚举值。我发现了一个关于使用 EnumJsonAdapter 的 Moshi 问题,但我没有看到任何 public class 供我使用。

我正在使用 Moshi 1.8.0

关于如何实现这个的任何想法或者编写自定义 JSON 适配器是唯一的方法吗?

有一个适配器工件用于额外的适配器,例如 EnumJsonAdapter

https://github.com/square/moshi/tree/master/moshi-adapters/src/main/java/com/squareup/moshi/adapters