On android when using Parceler, is it possible to annotate an interface using @Parceler
and have it pick up possible @ParcelConstructor
and @ParcelFactory
annotations in implementation classes?
The goal is to avoid writing a custom ParcelConverter to re-use generic field mapping in Parceler, but it appears that things like the implementations=
argument to @Parcel
are directed more towards mapping subtypes to supertypes (rather than the other way around):
@Parcel // can this be used to serialize **all** implementations ...
public interface MyIface {
String getProperty1();
int getProperty2();
}
public class MyImpl implements MyIface {
@ParcelFactory // and can this be used to deserialize the interface?
public static MyImpl fromParcelerValues(final String property1, final int property2) {
...
}
}
Of course there might be ambiguities if there are multiple matching mappings, but I can't seem to find any docs around getting this functionality to work even without any ambiguities.
You are correct, Parceler only operates on classes directly annotated with @Parcel
and the implementations
parameter (which is now depreciated and will shortly be removed from the api) is meant for something else.
I'll update this answer if you give a concrete example of what problem you're looking to solve around "generic field mapping".