Package dev.drtheo.autojson
Class AutoJSON
java.lang.Object
dev.drtheo.autojson.AutoJSON
- All Implemented Interfaces:
DelegateLogger,Logger,SchemaHolder
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayer(int layer) protected <T> Schema<T>createSchema(Type type) protected voidRegisters the default schemas (likeUUIDSchemaforUUIDs and such).protected voidRegisters the default templates (likeJavaMapSchemaforMaps and such).<F,T> F fromJson(JsonAdapter<F, T> adapter, T obj, Class<F> clazz) intgetLayer()static booleanlogger()booleanbooleansafeInstancing(Class<?> type) <T> Schema<T><T> Schema<T>Registers a new schema.voidsetLayer(int layer) voidsetLogMisingEntries(boolean logMisingEntries) voidsetSafeInstancing(boolean safeInstancing) protected LoggerbooleanshouldExclude(Field field, int layer) <T> voidtemplate(Class<? super T> type, AutoJSON.TemplateCreator<T> func) Registers a new template.<F,T> T toJson(JsonAdapter<F, T> adapter, Object obj) <F,T> T toJson(JsonAdapter<F, T> adapter, Object obj, Class<?> clazz) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.drtheo.autojson.logger.DelegateLogger
log, log, warn, warn
-
Constructor Details
-
AutoJSON
public AutoJSON()
-
-
Method Details
-
isBuiltIn
- Returns:
truewhen thetypeis a primitive (boxed or not) or if it's aString.
-
setupLogger
-
setLogMisingEntries
public void setLogMisingEntries(boolean logMisingEntries) - Parameters:
logMisingEntries- whether to log missing entries.- See Also:
-
logMissingEntries
public boolean logMissingEntries()- Returns:
- Whether to log missing object entries. Used by
BakedClassAutoSchema.
-
setSafeInstancing
public void setSafeInstancing(boolean safeInstancing) - Parameters:
safeInstancing- whether to use safe instancing for all objects.- See Also:
-
safeInstancing
- Returns:
- Whether to use safe instancing for the
type. - See Also:
-
setLayer
public void setLayer(int layer) - Parameters:
layer- the new layer(s) of thisAutoJSONinstance.- See Also:
-
addLayer
public void addLayer(int layer) - Parameters:
layer- the layer(s) to add to thisAutoJSONinstance.- See Also:
-
getLayer
public int getLayer() -
defaultSchemas
protected void defaultSchemas()Registers the default schemas (likeUUIDSchemaforUUIDs and such). -
defaultTemplates
protected void defaultTemplates()Registers the default templates (likeJavaMapSchemaforMaps and such). -
shouldExclude
- Returns:
- Whether to exclude the
layer. - API Note:
- Read here for more info about layers.
-
template
Registers a new template. Used for generics, when the type erasure is in action.- Type Parameters:
T- the type this template supports.- Parameters:
type- the base type.func- the lambda that creates a new schema based on the generic type.- See Also:
-
schema
Registers a new schema.- Type Parameters:
T- the type this schema supports.- Parameters:
type- the base type.schema- the schema used for serialization of this type.- See Also:
-
schema
- Specified by:
schemain interfaceSchemaHolder- Type Parameters:
T- the type the schema should be able to deserialize.- Parameters:
type- the type for this schema. Can be a generic.- Returns:
- the schema used for serialization of this type.
Returns
nullif thetypeis a primitive or a built-in type. - See Also:
- Implementation Note:
- By default, this method checks whether the type is a built-in, in
which case it returns
null. Otherwise, it checks the cache and creates a new schema if it's absent viaUnsafeUtil.computeIfAbsent(Map, Object, Function)andcreateSchema(Type).
-
createSchema
-
toJson
- Type Parameters:
F- the type the adapter deserializes from.T- the type the adapter serializes to.- Parameters:
adapter- the adapter used to serialize the object.obj- the object to serialize.- Returns:
- the serialized object.
- Implementation Note:
- Equivalent to calling
toJson(JsonAdapter, Object, Class)with theclassparameter beingobj.getClass().
-
toJson
- Type Parameters:
F- the type the adapter serializes from.T- the type the adapter serializes to.- Parameters:
adapter- the adapter used to serialize the object.obj- the object to serialize.clazz- the type to serialize via.- Returns:
- the serialized object.
- Implementation Note:
- Equivalent to calling
JsonAdapter.toJson(Object, Type).
-
fromJson
- Type Parameters:
F- the type the adapter deserializes to.T- the type the adapter deserializes from.- Parameters:
adapter- the adapter used to serialize the object.obj- the object to deserialize.clazz- the type to deserialize via.- Returns:
- the deserialized object.
- Implementation Note:
- Equivalent to calling
JsonAdapter.fromJson(Object, Class).
-
logger
- Specified by:
loggerin interfaceDelegateLogger
-