在android上使用Parceler时,是否可以使用@Parceler
对接口进行注释,并让它在实现类中拾取可能的@ParcelConstructor
和@ParcelFactory
注释?
目标是避免编写自定义的ParcelConverter来重用Parceler中的通用字段映射,但像implementations=
参数到@Parcel
这样的东西似乎更倾向于将子类型映射到超类型(而不是相反):
@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) {
...
}
}
当然,如果有多个匹配的映射,可能会有歧义,但我似乎找不到任何关于让这个功能发挥作用的文档,即使没有任何歧义。
您是对的,Parceler只对直接用@Parcel
注释的类进行操作,而implementations
参数(现在已折旧,很快将从api中删除)用于其他用途。
如果你给出一个具体的例子,说明你想围绕"通用字段映射"解决什么问题,我会更新这个答案。