schemaOfClass

Creates the schema that fits the given class.

Supported types

Primitives

Collections

Generics

A Class has no type arguments, so Map and Collection are rejected here. Use schemaOfType if you have a kotlin.reflect.KType. Reflected class fields go through it. Otherwise build the schema yourself, as in MapSchema(StringSchema, DoubleSchema).

Classes

The casts inside are unchecked, but the returned schema always matches the class.

Cost

A class schema reflects over every field. Results are cached per class in the registry, so that cost is paid once.

Examples

// Primitive types
val intSchema = FateSchema.schemaOfClass(Int::class.java) // IntSchema
val stringSchema = FateSchema.schemaOfClass(String::class.java) // StringSchema

// Collections
val arraySchema = FateSchema.schemaOfClass(Array<String>::class.java) // ArraySchema<String>
val enumSchema = FateSchema.schemaOfClass(MyEnum::class.java) // EnumSchema<MyEnum>

// Custom classes
val userSchema = FateSchema.schemaOfClass(User::class.java) // ReflectedClassSchema<User>
val typedSchema = FateSchema.schemaOfClass(TypedClass::class.java) // TypedClassSchema<TypedClass>

Return

A schema instance capable of serializing objects of type T

Parameters

T

The type parameter matching the class

clazz

The Java class to create a schema for

See also

Throws

if the class type is not supported


Creates the schema that fits the given class.

Supported types

Primitives

Collections

Generics

A Class has no type arguments, so Map and Collection are rejected here. Use schemaOfType if you have a kotlin.reflect.KType. Reflected class fields go through it. Otherwise build the schema yourself, as in MapSchema(StringSchema, DoubleSchema).

Classes

The casts inside are unchecked, but the returned schema always matches the class.

Cost

A class schema reflects over every field. Results are cached per class in the registry, so that cost is paid once.

Examples

// Primitive types
val intSchema = FateSchema.schemaOfClass(Int::class.java) // IntSchema
val stringSchema = FateSchema.schemaOfClass(String::class.java) // StringSchema

// Collections
val arraySchema = FateSchema.schemaOfClass(Array<String>::class.java) // ArraySchema<String>
val enumSchema = FateSchema.schemaOfClass(MyEnum::class.java) // EnumSchema<MyEnum>

// Custom classes
val userSchema = FateSchema.schemaOfClass(User::class.java) // ReflectedClassSchema<User>
val typedSchema = FateSchema.schemaOfClass(TypedClass::class.java) // TypedClassSchema<TypedClass>

Return

A schema instance capable of serializing objects of type T

Parameters

T

The type parameter matching the class

cls

The class to create a schema for

See also

Throws

if the class type is not supported


Convenience method for creating a schema from a reified type parameter.

See also