Class JBBPMapper

java.lang.Object
com.igormaznitsa.jbbp.mapper.JBBPMapper

public final class JBBPMapper extends Object
The Class processes mapping of a parsed binary data to class fields.
Since:
1.0
  • Field Details

    • MAKE_CLASS_INSTANCE_METHOD_NAME

      public static final String MAKE_CLASS_INSTANCE_METHOD_NAME
      See Also:
    • FLAG_IGNORE_MISSING_VALUES

      public static final int FLAG_IGNORE_MISSING_VALUES
      Flag to not throw exception if structure doesn't have value for a field.
      Since:
      1.1
      See Also:
  • Constructor Details

    • JBBPMapper

      public JBBPMapper()
  • Method Details

    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, String structPath, T instance, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure for its path to its fields and return the instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be used as the root, must not be null
      structPath - the path of a structure inside the root to be mapped to the class, must not be null
      instance - object to be filled by values, must not be null
      instantiators - functions to produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the mapping class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, String structPath, T instance, int flags, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure for its path to its fields and return the instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be used as the root, must not be null
      structPath - the path of a structure inside the root to be mapped to the class, must not be null
      instance - object to be filled by values, must not be null
      flags - special flags to tune mapping process
      instantiators - functions to produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the mapping class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
      See Also:
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, String structPath, T instance, JBBPMapperCustomFieldProcessor customFieldProcessor, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure for its path to its fields and return the instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be used as the root, must not be null
      structPath - the path of a structure inside the root to be mapped to the class, must not be null
      instance - instance to be filled by values, must not be null
      customFieldProcessor - a custom field processor to provide custom values, it can be null if there is not any mapping field desires the processor
      instantiators - functions produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the mapping class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, String structPath, T instance, JBBPMapperCustomFieldProcessor customFieldProcessor, int flags, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure for its path to its fields and return the instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be used as the root, must not be null
      structPath - the path of a structure inside the root to be mapped to the class, must not be null
      instance - object to be filled by values, must not be null
      customFieldProcessor - a custom field processor to provide custom values, it can be null if there is not any mapping field desires the processor
      flags - special flags to tune mapping
      instantiators - functions produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the mapping class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
      See Also:
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, T instance, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure to the instance and return it. It will create a class instance through a hack method and its constructor will not be called, thus use the method carefully.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be mapped to the class instance, must not be null
      instance - object instance to be filled by values, must not be null
      instantiators - functions produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct root, T instance, int flags, Function<Class<?>,Object>... instantiators)
      Create a class instance, map binary data of a structure to the instance and return it. It will create a class instance through a hack method and its constructor will not be called, thus use the method carefully.
      Type Parameters:
      T - the mapping class type
      Parameters:
      root - a parsed structure to be mapped to the class instance, must not be null
      instance - the class to be instantiated and mapped, must not be null
      flags - special flags to tune mapping process
      instantiators - functions produce class instance by request, must not be null
      Returns:
      the created and mapped instance of the class
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.0
      See Also:
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct rootStructure, T instance, JBBPMapperCustomFieldProcessor customFieldProcessor, Function<Class<?>,Object>... instantiators)
      Map a structure to a class instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      rootStructure - a structure to be mapped, must not be null
      instance - a class instance to be destination for map operations, must not be null
      customFieldProcessor - a custom field processor to provide custom values, it can be null if there is not any mapping field desires the processor
      instantiators - functions to produce class instance by request, must not be null
      Returns:
      the processed class instance, the same which was the argument for the method.
      Throws:
      JBBPMapperException - for any error
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct rootStructure, T instance, JBBPMapperCustomFieldProcessor customFieldProcessor, int flags, Function<Class<?>,Object>... instantiators)
      Map a structure to a class instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      rootStructure - a structure to be mapped, must not be null
      instance - a class instance to be destination for map operations, must not be null
      customFieldProcessor - a custom field processor to provide custom values, it can be null if there is not any mapping field desires the processor
      flags - special flags for mapping process
      instantiators - functions to produce class instance by request, must not be null
      Returns:
      the processed class instance, the same which was the argument for the method.
      Throws:
      JBBPMapperException - for any error
      Since:
      1.1
      See Also:
    • map

      @SafeVarargs public static <T> T map(JBBPFieldStruct rootStructure, T instance, JBBPMapperCustomFieldProcessor customFieldProcessor, int flags, BinFieldFilter binFieldFilter, Function<Class<?>,Object>... instantiators)
      Map a structure to a class instance.
      Type Parameters:
      T - the mapping class type
      Parameters:
      rootStructure - a structure to be mapped, must not be null
      instance - a class instance to be destination for map operations, must not be null
      customFieldProcessor - a custom field processor to provide custom values, it can be null if there is not any mapping field desires the processor
      flags - special flags for mapping process
      binFieldFilter - filter allows to exclude some fields from process, can be null
      instantiators - functions to produce class instance by request, must not be null
      Returns:
      the processed class instance, the same which was the argument for the method.
      Throws:
      JBBPMapperException - for any error
      Since:
      2.0.4
      See Also:
    • getFieldCacheSize

      public static int getFieldCacheSize()
      Get current number of classes which fields are cached in internal field cache.
      Returns:
      number of classes
      Since:
      2.0.0
    • clearFieldCache

      public static void clearFieldCache()
      Clear internal class field cache.
      Since:
      2.0.0
    • findAffectedFields

      public static List<MappedFieldRecord> findAffectedFields(Object instance, BinFieldFilter binFieldFilter)