# GenericRemoteMessage

Summary:[Fields](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#lfields)\|[Ctors](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#pubctors)\|[Methods](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#)  

# GenericRemoteMessage

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
GenericRemoteMessage
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


implements

`[To](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To)`<MessageLite>


`

|---|-----------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.remote.GenericRemoteMessage |

<br />

*** ** * ** ***

Generic implementation of the[EspressoRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/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](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage)class which implements the[EspressoRemoteMessage.To](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To)and[EspressoRemoteMessage.From](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.From)interfaces to serialize/deserialization any state into their proto message equivalent.

This[GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage)class is special type of[EspressoRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage), which implements the the[EspressoRemoteMessage.To](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To)and[EspressoRemoteMessage.From](https://developer.android.com/reference/android/support/test/espresso/remote/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](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptorRegistry)for[RemoteDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor)lookups. Where a[RemoteDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor)is a descriptor object which contains all the necessary meta information for proto serialization.

Usage:

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](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage)need to be of type`byte`and the type names must match the variable name of the serializable fields in`Foo.java`.

The last step is to create a[RemoteDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor)using a[RemoteDescriptor.Builder](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor.Builder), to configure all the meta data required for generic serialization. Finally register the descriptor with the[RemoteDescriptorRegistry](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptorRegistry). A typical descriptor builder looks like this:  

    new RemoteDescriptor.Builder()
       .setInstanceType(Foo.class)
       .setInstanceFieldDescriptors(
         FieldDescriptor.of(String.class, "bar")),
         FieldDescriptor.of(int.class, 32))
       .setRemoteType(GenericRemoteMessage.class)
       .setProtoType(FooProto.class)
       .build();
     
First set the instance type,`Foo.class`. Then specify the serializable fields using a[FieldDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/FieldDescriptor). Where a[FieldDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/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)](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor.Builder#setInstanceFieldDescriptors(android.support.test.espresso.remote.FieldDescriptor...))will be serialised into`FooProto.proto`. Next specify that type`Foo`will use for it's serialization entry point, in this case[GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/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!

## Summary

|                                                                                                                                                                                                          ### Fields                                                                                                                                                                                                           ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static final `[From](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.From)`<`[Object](https://developer.android.com/reference/java/lang/Object.html)`, MessageLite>` | [FROM](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#FROM) This is used to create and deserialize a proto message into an instance type |

|                                                                                                                                                                                        ### Public constructors                                                                                                                                                                                        ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#GenericRemoteMessage(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object.html)` instance) ` Creates a new[GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage). |

|                                                                  ### Public methods                                                                   ||
|----------------|---------------------------------------------------------------------------------------------------------------------------------------|
| ` MessageLite` | ` `[toProto](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#toProto())`() ` <br /> |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage#)From interface` `[android.support.test.espresso.remote.EspressoRemoteMessage.To](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To)` ` |-------------------------|------------------------------------------------------------------------------------------------------------------------------------| | ` abstract MessageLite` | ` `[toProto](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To#toProto())`() ` | ||

## Fields

### FROM

```
From<Object, MessageLite> FROM
```

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

<br />

## Public constructors

### GenericRemoteMessage

```
GenericRemoteMessage (Object instance)
```

Creates a new[GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage).

This constructor is called reflectively and should not be used.

<br />

|                                    Parameters                                    ||
|------------|----------------------------------------------------------------------|
| `instance` | `Object`: the object that needs to be serialized into a proto <br /> |

## Public methods

### toProto

```
MessageLite toProto ()
```

<br />

<br />

|        Returns        ||
|---------------|--------|
| `MessageLite` | <br /> |

-

  ## Interfaces

  - [Bindable](https://developer.android.com/reference/android/support/test/espresso/remote/Bindable)
  - [Converter](https://developer.android.com/reference/android/support/test/espresso/remote/Converter)
  - [EspressoRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage)
  - [EspressoRemoteMessage.From](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.From)
  - [EspressoRemoteMessage.To](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemoteMessage.To)
  - [RemoteInteraction](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteInteraction)
-

  ## Classes

  - [ConstructorInvocation](https://developer.android.com/reference/android/support/test/espresso/remote/ConstructorInvocation)
  - [EspressoRemote](https://developer.android.com/reference/android/support/test/espresso/remote/EspressoRemote)
  - [FieldDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/FieldDescriptor)
  - [GenericRemoteMessage](https://developer.android.com/reference/android/support/test/espresso/remote/GenericRemoteMessage)
  - [InteractionRequest](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionRequest)
  - [InteractionRequest.Builder](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionRequest.Builder)
  - [InteractionResponse](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionResponse)
  - [InteractionResponse.Builder](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionResponse.Builder)
  - [InteractionResponse.RemoteError](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionResponse.RemoteError)
  - [NoopRemoteInteraction](https://developer.android.com/reference/android/support/test/espresso/remote/NoopRemoteInteraction)
  - [ProtoUtils](https://developer.android.com/reference/android/support/test/espresso/remote/ProtoUtils)
  - [RemoteDescriptor](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor)
  - [RemoteDescriptor.Builder](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptor.Builder)
  - [RemoteDescriptorRegistry](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteDescriptorRegistry)
  - [RemoteInteractionRegistry](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteInteractionRegistry)
  - [TypeProtoConverters](https://developer.android.com/reference/android/support/test/espresso/remote/TypeProtoConverters)
-

  ## Enums

  - [InteractionResponse.Status](https://developer.android.com/reference/android/support/test/espresso/remote/InteractionResponse.Status)
-

  ## Exceptions

  - [NoRemoteEspressoInstanceException](https://developer.android.com/reference/android/support/test/espresso/remote/NoRemoteEspressoInstanceException)
  - [RemoteEspressoException](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteEspressoException)
  - [RemoteProtocolException](https://developer.android.com/reference/android/support/test/espresso/remote/RemoteProtocolException)