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
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
FieldDiscoverer.FieldCollector<I,V>
A collector for the necessary metadata for fields.static interface
FieldDiscoverer.InstanceFactory<I>
A handler that controls the deserialization process for an object.static interface
FieldDiscoverer.MutableInstanceFactory<I>
A handler for working with mutable objects in the object mapper.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <V> @Nullable FieldDiscoverer.InstanceFactory<I>
discover(java.lang.reflect.AnnotatedType target, FieldDiscoverer.FieldCollector<I,V> collector)
Inspect thetarget
type for fields to be supplied to thecollector
.static FieldDiscoverer<?>
emptyConstructorObject()
Create a new discoverer for object instance fields.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.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.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.static FieldDiscoverer<?>
record()
Create a new field discoverer that will handle record classes.
-
-
-
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 providersinstanceUnavailableErrorMessage
- 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
-
emptyConstructorObject
static FieldDiscoverer<?> emptyConstructorObject()
Create a new discoverer for object instance fields.Only objects with empty constructors can be created.
- Returns:
- new discoverer
- Since:
- 4.0.0
- See Also:
for more details on which fields will be discovered.
-
discover
<V> @Nullable FieldDiscoverer.InstanceFactory<I> discover(java.lang.reflect.AnnotatedType target, FieldDiscoverer.FieldCollector<I,V> collector) throws SerializationException
Inspect thetarget
type for fields to be supplied to thecollector
.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 inspectcollector
- collector for discovered fields.- Returns:
- a factory for handling the construction of object instances, or
null
iftarget
is not of a handleable type. - Throws:
SerializationException
- if any fields have invalid data- Since:
- 4.0.0
-
-