Skip to content

Most visited

Recently visited



public final class GenericRemoteMessage
extends Object implements To<MessageLite>


Generic implementation of the EspressoRemoteMessage interface, which uses reflection for proto message serialization and deserialization.

Every Espresso matcher, view action or view assertion needs to support proto serialization to participate in any kind of cross process UI interaction using Espresso Remote.

Each serializable type T needs to provide two things. First a proto message declaration of type T. Second an EspressoRemoteMessage class which implements the EspressoRemoteMessage.To and EspressoRemoteMessage.From interfaces to serialize/deserialization any state into their proto message equivalent.

This GenericRemoteMessage class is special type of EspressoRemoteMessage, which implements the the EspressoRemoteMessage.To and EspressoRemoteMessage.From interfaces and uses reflection to perform serialisation of an object of type T into its proto message representation.

Espresso Remote uses a global RemoteDescriptorRegistry for RemoteDescriptor lookups. Where a RemoteDescriptor is a descriptor object which contains all the necessary meta information for proto serialization.


For a type Foo with fields bar and baz:

public class Foo {
   private final String bar;
   private final int baz;

   protected Foo(String bar, int baz) { // set fields }

Note: A protected constructor with serializable fields in declared order is required for proto deserialization.

Create a corresponding proto definition, FooProto.proto for Foo:

message FooProto {
   bytes bar = 1; // Name needs to match Foo#bar
   bytes baz = 2; // Name needs to match Foo#baz

The proto type definitions used with GenericRemoteMessage need to be of type byte and the type names must match the variable name of the serializable fields in

The last step is to create a RemoteDescriptor using a RemoteDescriptor.Builder, to configure all the meta data required for generic serialization. Finally register the descriptor with the RemoteDescriptorRegistry. A typical descriptor builder looks like this:

new RemoteDescriptor.Builder()
     FieldDescriptor.of(String.class, "bar")),
     FieldDescriptor.of(int.class, 32))

First set the instance type, Foo.class. Then specify the serializable fields using a FieldDescriptor. Where a FieldDescriptor represents the name and the type of a reflective field of Foo. Any fields described by the field properties and passed to setInstanceFieldDescriptors(FieldDescriptor) will be serialised into FooProto.proto. Next specify that type Foo will use for it's serialization entry point, in this case GenericRemoteMessage and lastly set the proto message class.

Note: The declared field properties order, must match the protected constructor of Foo, which takes the serializable fields in declared order!



public static final From<Object, MessageLite> FROM

This is used to create and deserialize a proto message into an instance type

Public constructors

GenericRemoteMessage(Object instance)

Creates a new GenericRemoteMessage.

Public methods

MessageLite toProto()

Inherited methods

From class java.lang.Object
From interface



From<Object, MessageLite> FROM

This is used to create and deserialize a proto message into an instance type

Public constructors


GenericRemoteMessage (Object instance)

Creates a new GenericRemoteMessage.

This constructor is called reflectively and should not be used.

instance Object: the object that needs to be serialized into a proto

Public methods


MessageLite toProto ()


This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)