2

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.

Del
  • 397
  • 2
  • 9
  • Could you provide an example of the generic field mapping you're interested in? – John Ericksen May 12 '16 at 22:59
  • I'm looking to say "I can serialize any instance of this interface uniformly", as well as registering deserialization methods to use with that interface ... but those methods might live best outside that interface type. How do I say "Parceler, serialize this interface type, and look over there to deserialize it"? the "generic mapping" just means I want to use Parceler to generate my code rather than hand-writing serialization code. – Del May 17 '16 at 22:17

1 Answers1

0

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

John Ericksen
  • 10,995
  • 4
  • 45
  • 75