schemaOfClass
Creates the schema that fits the given class.
Supported types
Primitives
int/Integer→ IntSchemalong/Long→ LongSchemadouble/Double→ DoubleSchemaboolean/Boolean→ BooleanSchemaString→ StringSchema
Collections
T[]→ ArraySchema, inferring the element schema recursively Enum<T>→ EnumSchema
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
An
AS_TYPEconstant, on a companion object or as a Java static → TypedClassSchemaAnything else → ReflectedClassSchema
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
The type parameter matching the class
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
int/Integer→ IntSchemalong/Long→ LongSchemadouble/Double→ DoubleSchemaboolean/Boolean→ BooleanSchemaString→ StringSchema
Collections
T[]→ ArraySchema, inferring the element schema recursively Enum<T>→ EnumSchema
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
An
AS_TYPEconstant, on a companion object or as a Java static → TypedClassSchemaAnything else → ReflectedClassSchema
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
The type parameter matching the class
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.