schemaOfClass
Automatically creates an appropriate schema for the given class type.
This factory method uses reflection and type inspection to determine the most suitable schema for a given Java class. It handles the complete type system including primitives, collections, enums, and custom classes.
Supported Types
Primitive Types:
int/Integer→ IntSchemalong/Long→ LongSchemadouble/Double→ DoubleSchemaboolean/Boolean→ BooleanSchemaString→ StringSchema
Collection Types:
T[]→ ArraySchema(recursive schema inference for element type) Enum<T>→ EnumSchema
Class Types:
Classes with companion object
as_typeproperty → TypedClassSchemaAll other classes → ReflectedClassSchema
Type Safety
The method uses unchecked casts internally but maintains type safety through careful type checking. The returned schema is guaranteed to be compatible with the input class type.
Performance Considerations
Primitive type mapping is constant-time
Enum and array detection uses class introspection
Class schema creation involves reflection and field analysis
Consider caching schemas for frequently used types
Usage 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
Automatically creates an appropriate schema for the given class type.
This factory method uses reflection and type inspection to determine the most suitable schema for a given Java class. It handles the complete type system including primitives, collections, enums, and custom classes.
Supported Types
Primitive Types:
int/Integer→ IntSchemalong/Long→ LongSchemadouble/Double→ DoubleSchemaboolean/Boolean→ BooleanSchemaString→ StringSchema
Collection Types:
T[]→ ArraySchema(recursive schema inference for element type) Enum<T>→ EnumSchema
Class Types:
Classes with companion object
as_typeproperty → TypedClassSchemaAll other classes → ReflectedClassSchema
Type Safety
The method uses unchecked casts internally but maintains type safety through careful type checking. The returned schema is guaranteed to be compatible with the input class type.
Performance Considerations
Primitive type mapping is constant-time
Enum and array detection uses class introspection
Class schema creation involves reflection and field analysis
Consider caching schemas for frequently used types
Usage 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.