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
I thought that moshi already had this in their adapters artifact, but no.
This should be a good addition, altho I don't think that adding an annotation would be a good approach. Maybe smth like DefaultOnNullJsonAdapterFactory.create(Type type, T fallback).
So would that be a global default for a type? That would be handy but I think I would also want to be able to specify that behaviour for a single field rather than every field as well.
The annotation api is pretty limited in java. A fallback for strings is possible, and for that, we can just extend the existing FallbackOnNull, but for objects, it's trickier. There's no way, that I know of, that would allow settings an object value as an annotation param.
I realise that FallbackOnNull seems to be geared towards primitives, but supporting any type would be great.
Maybe a separate adapter (DefaultOnNull) could work, where a default value for any type when it is null.
The text was updated successfully, but these errors were encountered: