Class INIToObjectMapper<T>

  • Type Parameters:
    T - the target type to be produced by this Mapper
    All Implemented Interfaces:
    Mapper<T>

    public class INIToObjectMapper<T>
    extends AbstractINIMapper<T>
    implements Mapper<T>
    A specialized Mapper that loads the contents of a valid INI Source (e.g.: file, URL) into a POJO (Plain-Old Java Object).

    Every property and section will be assigned to a field in the target object in either of the following cases:

    • the field is marked with the @Property annotation, defining a custom key to be mapped; or
    • the field name is equal to the property key (with no need to use an annotation in these cases)

    Notes:

    • The fields in the target object can be private (recommended)
    • Fields marked transient are ignored
    • If the associated property is missing in the source, the corresponding field assumes a default value as specified by The JavaTM Tutorials > Language Basics > Variables > Primitive Data Types, i.e., zero for numeric types, false for boolean, and null for String (or any object type).
    • If the a section is not mapped to dedicated object in the target class, the whole section will be skipped

    By default, new objects will be created by allocating a new instance directly in the heap, without calling a constructor, then assigning each field via reflection. To change this behavior, you may specify a different ObjectFactory in the constructor:

     new INIToObjectMapper(MyType.class, ObjectFactory.FAST); // Default
     new INIToObjectMapper(MyType.class, ObjectFactory.CONSTRUCTOR_BASED);
     
    Since:
    2.0.0
    Author:
    oswaldo.bapvic.jr (Oswaldo Junior)
    • Constructor Detail

      • INIToObjectMapper

        public INIToObjectMapper​(Class<T> targetType)
        Builds a new INIToObjectMapper with the specified target type.
        Parameters:
        targetType - the target type to be produced by this Mapper
      • INIToObjectMapper

        public INIToObjectMapper​(Class<T> targetType,
                                 ObjectFactory objectFactory)
        Builds a new INIToObjectMapper with the specified target type and a custom object factory.
        Parameters:
        targetType - the target type to be produced by this Mapper
        objectFactory - the ObjectFactory to produce objects; not null
        Since:
        2.5.0
    • Method Detail

      • apply

        public T apply​(InputStream inputStream)
                throws IOException
        Description copied from interface: Mapper
        Applies this Mapper into the given input.

        Note: The input stream must be closed by the caller after the mapping operation.

        Specified by:
        apply in interface Mapper<T>
        Parameters:
        inputStream - the input stream to be mapped
        Returns:
        the mapped object
        Throws:
        IOException - if a low-level I/O problem (such and unexpected end-of-input, or network error) occurs