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
                        
    • Constructor Detail

      • AutoJSON

        AutoJSON()
    • Method Detail

      • getLayer

         int getLayer()
        Returns:

        the current layers of this AutoJSON instance.

      • setLayer

         void setLayer(int layer)
        Parameters:
        layer - the new layer(s) of this AutoJSON instance.
      • 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 null if the type is 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.
      • setSafeInstancing

         void setSafeInstancing(boolean safeInstancing)
        Parameters:
        safeInstancing - whether to use safe instancing for all objects.