AppFunctionOneOfTypeMetadata


public final class AppFunctionOneOfTypeMetadata extends AppFunctionDataTypeMetadata


Defines the schema for a data type that can be one of several possible types, representing a form of polymorphism or a sealed hierarchy.

An object of this type must match exactly one of the schemas defined in the matchOneOf list. This is useful for modeling sealed classes or interfaces where an object can be one of a limited set of subtypes. This implies a hierarchical relationship between the parent type (represented by this OneOfTypeMetadata) and its possible concrete implementations in matchOneOf.

For example, consider the following sealed interface and its implementations:

package com.example.myapp

sealed interface Animal {
val name: String
}

data class Dog(
override val name: String,
val breed: String,
) : Animal

data class Cat(
override val name: String,
val livesLeft: Int,
) : Animal

The following AppFunctionOneOfTypeMetadata can be used to define a data type that matches any object implementing the Animal interface (i.e., either a Dog or a Cat).

val animalType = AppFunctionOneOfTypeMetadata(
qualifiedName = "com.example.myapp.Animal",
matchOneOf = listOf(
AppFunctionObjectTypeMetadata(
qualifiedName = "com.example.myapp.Dog",
properties = mapOf(
"name" to AppFunctionStringTypeMetadata(...),
"breed" to AppFunctionStringTypeMetadata(...),
),
required = listOf("name", "breed"),
isNullable = false,
),
AppFunctionObjectTypeMetadata(
qualifiedName = "com.example.myapp.Cat",
properties = mapOf(
"name" to AppFunctionStringTypeMetadata(...),
"livesLeft" to AppFunctionIntTypeMetadata(...),
),
required = listOf("name", "livesLeft"),
isNullable = false,
),
),
isNullable = false,
)

This data type can be used to define the schema of an input or output type.

Summary

Public constructors

AppFunctionOneOfTypeMetadata(
    @NonNull List<@NonNull AppFunctionDataTypeMetadata> matchOneOf,
    @NonNull String qualifiedName,
    boolean isNullable,
    @NonNull String description
)

Public methods

boolean
equals(Object other)
final @NonNull List<@NonNull AppFunctionDataTypeMetadata>

The list of possible data types that an object can match.

final @NonNull String

The parent object's qualified name if available.

int
@NonNull String

Inherited methods

From androidx.appfunctions.metadata.AppFunctionDataTypeMetadata
final @NonNull String

A description of the data type and its intended use.

final boolean

Whether the data type is nullable.

Public constructors

AppFunctionOneOfTypeMetadata

public AppFunctionOneOfTypeMetadata(
    @NonNull List<@NonNull AppFunctionDataTypeMetadata> matchOneOf,
    @NonNull String qualifiedName,
    boolean isNullable,
    @NonNull String description
)

Public methods

equals

public boolean equals(Object other)

getMatchOneOf

Added in 1.0.0-alpha06
public final @NonNull List<@NonNull AppFunctionDataTypeMetadatagetMatchOneOf()

The list of possible data types that an object can match.

getQualifiedName

Added in 1.0.0-alpha06
public final @NonNull String getQualifiedName()

The parent object's qualified name if available. For example, "com.example.myapp.Animal".

Use this value to set androidx.appfunctions.AppFunctionData.qualifiedName when trying to build the parameters for androidx.appfunctions.ExecuteAppFunctionRequest.

hashCode

public int hashCode()

toString

public @NonNull String toString()