Interface ObjectMapper<V>
-
- Type Parameters:
V
- mapped type
- All Known Subinterfaces:
ObjectMapper.Mutable<V>
public interface ObjectMapper<V>
A mapper that converts between configuration nodes and Java objects.Object mappers are created through a
ObjectMapper.Factory
, either the default one or one created with additional options. See that class's documentation for details.The object mapper can be accessed directly, through its
factory()
, or through aConfigurationNode
'sConfigurationNode.get(TypeToken)
method. To use a custom factory instance through a node, a custom TypeSerializer has to be registered to theTypeSerializerCollection
used by the node.- Since:
- 4.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ObjectMapper.Factory
Provider for object mappers.static interface
ObjectMapper.Mutable<V>
An object mapper capable of loading data into an existing object.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
canCreateInstances()
Get whether or not this mapper is capable of creating new instances of its mapped type.static ObjectMapper.Factory.Builder
emptyFactoryBuilder()
Create an empty builder.static ObjectMapper.Factory
factory()
Get the default object mapper factory instance.static ObjectMapper.Factory.Builder
factoryBuilder()
Create a builder populated with default settings.List<? extends FieldData<?,V>>
fields()
Get the parameters that will be handled by this mapper.V
load(ConfigurationNode source)
Create a new object instance.Type
mappedType()
The generic type of object that this mapper instance handles.void
save(V value, ConfigurationNode target)
Write data from the provided object to the target.
-
-
-
Method Detail
-
factory
static ObjectMapper.Factory factory()
Get the default object mapper factory instance.This factory has the following characteristics:
- can resolve fields in empty-constructor objects and Records
- will try to resolve any field in objects
- supports
NodeKey
andSetting
annotations for customizing node resolution - uses the
NamingSchemes.LOWER_CASE_DASHED
naming scheme for other nodes - supports unlocalized
Matches
, andRequired
constraints - processes
Comment
annotations
- Returns:
- default factory
- Since:
- 4.0.0
-
emptyFactoryBuilder
static ObjectMapper.Factory.Builder emptyFactoryBuilder()
Create an empty builder.This applies none of the standard formats, processors, constraints or resolvers. Unless you want to do something particularly specialized, you should probably be using
factoryBuilder()
.- Returns:
- new empty builder
- Since:
- 4.0.0
-
factoryBuilder
static ObjectMapper.Factory.Builder factoryBuilder()
Create a builder populated with default settings.This builder is prepared to allow overriding any of the default object mapper features.
- Returns:
- new builder
- Since:
- 4.0.0
- See Also:
for a description of the default settings
-
load
V load(ConfigurationNode source) throws SerializationException
Create a new object instance.- Parameters:
source
- object source- Returns:
- new instance
- Throws:
SerializationException
- if any invalid data is present. Loading is done in stages, so any deserialization errors will occur before anything is written to objects.- Since:
- 4.0.0
-
save
void save(V value, ConfigurationNode target) throws SerializationException
Write data from the provided object to the target.- Parameters:
value
- value typetarget
- destination- Throws:
SerializationException
- if unable to fully save- Since:
- 4.0.0
-
fields
List<? extends FieldData<?,V>> fields()
Get the parameters that will be handled by this mapper.- Returns:
- immutable list of fields
- Since:
- 4.0.0
-
mappedType
Type mappedType()
The generic type of object that this mapper instance handles.- Returns:
- object type
- Since:
- 4.0.0
-
canCreateInstances
boolean canCreateInstances()
Get whether or not this mapper is capable of creating new instances of its mapped type.If this returns
false
,load(ConfigurationNode)
will always fail.- Returns:
- if the mapped type can be instantiated.
- Since:
- 4.0.0
-
-