Interface FieldDiscoverer<I>

  • Type Parameters:
    I - intermediate data type

    public interface FieldDiscoverer<I>
    Interface that gathers metadata from classes.

    Any type of data object can be added this way.

    Since:
    4.0.0
    • Method Detail

      • record

        static FieldDiscoverer<?> record()
        Create a new field discoverer that will handle record classes.

        This discoverer will use the record's canonical constructor to create new instances, passing null for any missing parameters. The accessor methods for each record component will be used to read values from the record.

        Returns:
        new discoverer
        Since:
        4.0.0
      • object

        static FieldDiscoverer<?> object​(CheckedFunction<java.lang.reflect.AnnotatedType,​@Nullable java.util.function.Supplier<java.lang.Object>,​SerializationException> instanceFactory)
        Create a new discoverer for object instance fields.

        This discoverer will process any non-static and non-transient field in the object. Modifying final fields is unsupported and may stop working with newer Java versions.

        Parameters:
        instanceFactory - a factory for instance providers
        Returns:
        new discoverer
        Since:
        4.0.0
      • object

        static FieldDiscoverer<?> object​(CheckedFunction<java.lang.reflect.AnnotatedType,​@Nullable java.util.function.Supplier<java.lang.Object>,​SerializationException> instanceFactory,
                                         java.lang.String instanceUnavailableErrorMessage)
        Create a new discoverer for object instance fields.

        This discoverer will process any non-static and non-transient field in the object. Modifying final fields is unsupported and may stop working with newer Java versions.

        Parameters:
        instanceFactory - a factory for instance providers
        instanceUnavailableErrorMessage - a message that will be part of the exception thrown when trying to create instances for an unsupported type
        Returns:
        new discoverer
        Since:
        4.1.0
      • instantiableObject

        static FieldDiscoverer<?> instantiableObject​(CheckedFunction<java.lang.reflect.AnnotatedType,​@Nullable java.util.function.Supplier<java.lang.Object>,​SerializationException> instanceFactory)
        Create a new discoverer for object instance fields.

        This discoverer will process any non-static and non-transient field in the object. Modifying final fields is unsupported and may stop working with newer Java versions.

        This discoverer will only match objects that it can create an instance of (i. e. where instanceFactory returns a non-null supplier).

        Parameters:
        instanceFactory - a factory for instance providers
        Returns:
        new discoverer
        Since:
        4.2.0
      • discover

        <V> @Nullable FieldDiscoverer.InstanceFactory<Idiscover​(java.lang.reflect.AnnotatedType target,
                                                                  FieldDiscoverer.FieldCollector<I,​V> collector)
                                                           throws SerializationException
        Inspect the target type for fields to be supplied to the collector.

        If the target type is handleable, a non-null value must be returned. Fields can only be collected from one source at the moment, so if the instance factory is null any discovered fields will be discarded.

        Type Parameters:
        V - object type
        Parameters:
        target - type to inspect
        collector - collector for discovered fields.
        Returns:
        a factory for handling the construction of object instances, or null if target is not of a handleable type.
        Throws:
        SerializationException - if any fields have invalid data
        Since:
        4.0.0