Package dev.drtheo.autojson.schema.base
Interface Schema<T>
- Type Parameters:
T- the type this schema serializes.
- All Known Subinterfaces:
ArraySchema<T,,Intermediary> ArraySchema.Simple<T>,ObjectSchema<T>,PrimitiveSchema<T>,StringSchema<T>,WrapperSchema<T>
- All Known Implementing Classes:
AbstractMapSchema,BakedClassAutoSchema,JavaArraySchema,JavaEnumSchema,JavaListSchema,JavaMapSchema,JavaSetSchema,String2ObjectMapSchema,UUIDSchema
public sealed interface Schema<T>
permits ArraySchema<T,Intermediary>, ObjectSchema<T>, PrimitiveSchema<T>, WrapperSchema<T>
The base schema class.
You should probably implement
You should probably implement
ObjectSchema, ArraySchema,
PrimitiveSchema, WrapperSchema or one of their derivatives instead.-
Method Summary
Modifier and TypeMethodDescriptiondefault ArraySchema<T,?> asArray()default ObjectSchema<T>asObject()default PrimitiveSchema<T>static <T> TcreateInstance(Class<? extends T> clazz, boolean safe) Creates a new class ofT.serialize(JsonAdapter<Object, To> adapter, JsonSerializationContext ctx, T t) type()The type of the schema.
-
Method Details
-
asArray
-
asObject
-
asPrimitive
-
type
SchemaType type()The type of the schema.
Instead of doing if-instanceof checks for the schema implementations, the adapters should use theSchemaTypewith a switch statement instead.- Returns:
- the type of this schema.
-
serialize
<To> JsonSerializationContext.Built serialize(JsonAdapter<Object, To> adapter, JsonSerializationContext ctx, T t) -
createInstance
Creates a new class ofT.- Type Parameters:
T- the type of the class you want to instantiate.- Parameters:
clazz- the class you want to instantiate.safe- whether to use a safe or fast method.- Returns:
- A new instance of the specified class.
- Implementation Note:
- When using the safe method, it will create a new instance by
invoking the constructor via reflections. Otherwise, it will allocate
a new instance using
Unsafe, which is faster, but won't call the constructor, meaning that all fields will get their default values (0for numbers,falsefor booleans andnullfor objects).
-