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

FallbackOnNull should support Strings #70

Open
josh-burton opened this issue Oct 1, 2018 · 3 comments
Open

FallbackOnNull should support Strings #70

josh-burton opened this issue Oct 1, 2018 · 3 comments

Comments

@josh-burton
Copy link

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.

@serj-lotutovici
Copy link
Owner

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).

Wanna submit a PR?

@josh-burton
Copy link
Author

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.

@serj-lotutovici
Copy link
Owner

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.

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

No branches or pull requests

2 participants