You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way we can add some fallback value to a field (behaviour similar to enums) if the type does not exist for deserialization ? We want to add more types in new app releases but it breaks previous versions.
The text was updated successfully, but these errors were encountered:
This does not work. It still throws the error. I think you misunderstood my issue.
Suppose i have a base class say InputSource with @BuiltValue(instantiable: false) and I created a subclass from it eg. GalleryInputSource and released the app. But later if I wanted to add another subclass eg. CameraInputSource, it wont be backwards compatible and fail the entire deserialization on older apps. Is there a way I can handle these cases ? I was hoping if we can add a flag to ignore DeserializationError and continue with the default value.
I don't see any good way to do that today; here are a few workarounds that come to mind:
you could send a list of the class names to the client, e.g. ['CameraInputSource'], and for each one it could check if a serializer is available, and if not install a Serializer<Null> that returns that string for wire name, and always deserializes to null
or, you could write a custom serializer for InputSource that looks up the serializer and calls it if present, returns null if not found
or, you could write a serializer plugin that removes unknown JSON using a local list of valid classes
in terms of supporting as a feature ... I guess Serializers could have an option that you set once at runtime to return null on unknown type instead of throwing? You would have to make sure the field or collection of InputSource is nullable. Or we could do something like that but just for collections.
Is there a way we can add some fallback value to a field (behaviour similar to enums) if the type does not exist for deserialization ? We want to add more types in new app releases but it breaks previous versions.
The text was updated successfully, but these errors were encountered: