Package dev.drtheo.autojson
Class AutoJSON
-
- All Implemented Interfaces:
-
dev.drtheo.autojson.SchemaHolder,dev.drtheo.autojson.logger.DelegateLogger,dev.drtheo.autojson.logger.Logger
public class AutoJSON implements SchemaHolder, DelegateLogger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceAutoJSON.TemplateCreator
-
Field Summary
Fields Modifier and Type Field Description public intlayer
-
Constructor Summary
Constructors Constructor Description AutoJSON()
-
Method Summary
Modifier and Type Method Description intgetLayer()voidsetLayer(int layer)static booleanisBuiltIn(Type type)booleanlogMissingEntries()booleanuseCustomEnumMap()booleanuseLossyNumbers()booleanuseCustomFieldMap()booleansafeInstancing(Class<out Object> type)voidaddLayer(int layer)booleanshouldExclude(Field field, int layer)<T> voidtemplate(Class<in T> type, AutoJSON.TemplateCreator<T> func)Registers a new template. <T> Schema<T>schema(Type type, Schema<T> schema)Registers a new schema. <T> Schema<T>schema(Type type)<F, T> TtoJson(JsonAdapter<F, T> adapter, Object obj)<F, T> TtoJson(JsonAdapter<F, T> adapter, Object obj, Class<out Object> clazz)<F, T> FfromJson(JsonAdapter<F, T> adapter, T obj, Class<F> clazz)Loggerlogger()voidsetLogMisingEntries(boolean logMisingEntries)voidsetUseCustomEnumMap(boolean useCustomEnumMap)voidsetLossyNumbers(boolean lossyNumbers)voidsetUseCustomFieldMap(boolean useCustomFieldMap)voidsetSafeInstancing(boolean safeInstancing)-
Methods inherited from class dev.drtheo.autojson.logger.DelegateLogger
log, log, warn, warn -
Methods inherited from class dev.drtheo.autojson.logger.Logger
log, warn -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
isBuiltIn
static boolean isBuiltIn(Type type)
- Returns:
truewhen thetypeis a primitive (boxed or not) or if it's a String or a LazilyParsedNumber.
-
logMissingEntries
boolean logMissingEntries()
- Returns:
Whether to log missing object entries. Used by BakedClassAutoSchema.
-
useCustomEnumMap
boolean useCustomEnumMap()
-
useLossyNumbers
boolean useLossyNumbers()
-
useCustomFieldMap
boolean useCustomFieldMap()
-
safeInstancing
boolean safeInstancing(Class<out Object> type)
- Returns:
Whether to use safe instancing for the
type.
-
addLayer
void addLayer(int layer)
- Parameters:
layer- the layer(s) to add to this AutoJSON instance.
-
shouldExclude
boolean shouldExclude(Field field, int layer)
- Returns:
Whether to exclude the
layer.
-
template
<T> void template(Class<in T> type, AutoJSON.TemplateCreator<T> func)
Registers a new template. Used for generics, when the type erasure is in action.
- Parameters:
type- the base type.func- the lambda that creates a new schema based on the generic type.
-
schema
<T> Schema<T> schema(Type type, Schema<T> schema)
Registers a new schema.
- Parameters:
type- the base type.schema- the schema used for serialization of this type.
-
schema
<T> Schema<T> schema(Type type)
- Parameters:
type- the type for this schema.- Returns:
the schema used for serialization of this type. Returns
nullif thetypeis a primitive or a built-in type.
-
toJson
<F, T> T toJson(JsonAdapter<F, T> adapter, Object obj)
- Parameters:
adapter- the adapter used to serialize the object.obj- the object to serialize.- Returns:
the serialized object.
-
toJson
<F, T> T toJson(JsonAdapter<F, T> adapter, Object obj, Class<out Object> clazz)
- Parameters:
adapter- the adapter used to serialize the object.obj- the object to serialize.clazz- the type to serialize via.- Returns:
the serialized object.
-
fromJson
<F, T> F fromJson(JsonAdapter<F, T> adapter, T obj, Class<F> clazz)
- Parameters:
adapter- the adapter used to serialize the object.obj- the object to deserialize.clazz- the type to deserialize via.- Returns:
the deserialized object.
-
setLogMisingEntries
void setLogMisingEntries(boolean logMisingEntries)
- Parameters:
logMisingEntries- whether to log missing entries.
-
setUseCustomEnumMap
void setUseCustomEnumMap(boolean useCustomEnumMap)
-
setLossyNumbers
void setLossyNumbers(boolean lossyNumbers)
-
setUseCustomFieldMap
void setUseCustomFieldMap(boolean useCustomFieldMap)
-
setSafeInstancing
void setSafeInstancing(boolean safeInstancing)
- Parameters:
safeInstancing- whether to use safe instancing for all objects.
-
-
-
-