Types

Factory methods for types.

class Types

Functions

arrayComponentType
Link copied to clipboard

Returns the element type of {@code type} if it is an array type, or null if it is not an array type.

open fun arrayComponentType(type: Type): Type
arrayOf
Link copied to clipboard

Returns an array type whose elements are all instances of {@code componentType} .

open fun arrayOf(componentType: Type): GenericArrayType
collectionElementType
Link copied to clipboard

Returns the element type of this collection type.

open fun collectionElementType(context: Type, contextRawType: Class<out Any>): Type
createJsonQualifierImplementation
Link copied to clipboard
open fun <T : Annotation?> createJsonQualifierImplementation(annotationType: Class<T>): T
equals
Link copied to clipboard

Returns true if {@code a} and {@code b} are equal.

open fun equals(a: Type, b: Type): Boolean
generatedJsonAdapterName
Link copied to clipboard

Resolves the generated JsonAdapter fully qualified class name for a given {@code clazz} . This is the same lookup logic used by both the Moshi code generation as well as lookup for any JsonClass-annotated classes. This can be useful if generating your own JsonAdapters without using Moshi's first party code gen.

open fun generatedJsonAdapterName(clazz: Class<out Any>): String

Resolves the generated JsonAdapter fully qualified class name for a given {@code className} . This is the same lookup logic used by both the Moshi code generation as well as lookup for any JsonClass-annotated classes. This can be useful if generating your own JsonAdapters without using Moshi's first party code gen.

open fun generatedJsonAdapterName(className: String): String
getFieldJsonQualifierAnnotations
Link copied to clipboard

the target class to read the {@code fieldName} field annotations from.

open fun getFieldJsonQualifierAnnotations(clazz: Class<out Any>, fieldName: String): Set<out Annotation>
getGenericSuperclass
Link copied to clipboard
open fun getGenericSuperclass(type: Type): Type
getRawType
Link copied to clipboard
open fun getRawType(type: Type): Class<out Any>
getSupertype
Link copied to clipboard

Returns the generic form of {@code supertype} . For example, if this is {@code * ArrayList} , this returns {@code Iterable} given the input {@code * Iterable.class} .

open fun getSupertype(context: Type, contextRawType: Class<out Any>, supertype: Class<out Any>): Type
mapKeyAndValueTypes
Link copied to clipboard

Returns a two element array containing this map's key and value types in positions 0 and 1 respectively.

open fun mapKeyAndValueTypes(context: Type, contextRawType: Class<out Any>): Array<Type>
newParameterizedType
Link copied to clipboard

Returns a new parameterized type, applying {@code typeArguments} to {@code rawType} . Use this method if {@code rawType} is not enclosed in another type.

open fun newParameterizedType(rawType: Type, typeArguments: Array<Type>): ParameterizedType
newParameterizedTypeWithOwner
Link copied to clipboard

Returns a new parameterized type, applying {@code typeArguments} to {@code rawType} . Use this method if {@code rawType} is enclosed in {@code ownerType} .

open fun newParameterizedTypeWithOwner(ownerType: Type, rawType: Type, typeArguments: Array<Type>): ParameterizedType
nextAnnotations
Link copied to clipboard

Checks if {@code annotations} contains {@code jsonQualifier} . Returns the subset of {@code * annotations} without {@code jsonQualifier} , or null if {@code annotations} does not contain {@code jsonQualifier} .

open fun nextAnnotations(annotations: Set<out Annotation>, jsonQualifier: Class<out Annotation>): Set<out Annotation>
subtypeOf
Link copied to clipboard

Returns a type that represents an unknown type that extends {@code bound} . For example, if {@code bound} is {@code CharSequence.class} , this returns {@code ? extends CharSequence} . If {@code bound} is {@code Object.class} , this returns {@code ?} , which is shorthand for {@code ? * extends Object} .

open fun subtypeOf(bound: Type): WildcardType
supertypeOf
Link copied to clipboard

Returns a type that represents an unknown supertype of {@code bound} . For example, if {@code * bound} is {@code String.class} , this returns {@code ? super String} .

open fun supertypeOf(bound: Type): WildcardType