public final class ObjectDeserializer
extends java.lang.Object
UnmodifiableConfig, Config, etc.) to Java objects.
class Position {
private final int x, y, z;
public Position(int x, int y, int z) {
this.x=x; this.y=y; this.z=z;
}
}
And a configuration like this:
Config conf = Config.inMemory();
conf.set("x", 12);
conf.set("y", -20);
conf.set("z", 42);
You can deserialize the Config to an instance of Position with:
Position deserialized = new ObjectDeserializer.standard().deserializeFields(conf, Position::new);
// result: Position(12, -20, 42)
Use builder() or blankBuilder() to precisely configure
the deserialization process.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
applyTransientModifier |
protected ValueDeserializerProvider<?,?> |
defaultProvider |
protected java.util.List<ValueDeserializerProvider<?,?>> |
generalProviders |
| Modifier and Type | Method and Description |
|---|---|
static ObjectDeserializerBuilder |
blankBuilder()
Creates a new
ObjectDeserializerBuilder without the standard deserializers already registered. |
static ObjectDeserializerBuilder |
builder()
Creates a new
ObjectDeserializerBuilder with some standard deserializers already registered. |
void |
deserializeFields(UnmodifiableConfig source,
java.lang.Object destination)
Deserializes a
Config as an object by transforming the config entries into fields. |
<R> R |
deserializeFields(UnmodifiableConfig source,
java.util.function.Supplier<? extends R> destinationSupplier)
Deserializes a
Config as an object of type R by transforming the config entries
into fields. |
<C extends java.util.Collection<V>,V> |
deserializeToCollection(java.lang.Object configValue,
java.lang.Class<C> collectionClass,
java.lang.Class<V> valueClass)
Deserializes a value into an instance of the collection
C<V>. |
<M extends java.util.Map<java.lang.String,V>,V> |
deserializeToMap(java.lang.Object configValue,
java.lang.Class<M> mapClass,
java.lang.Class<V> valueClass)
Deserializes a value into an instance of the map
M<String, V>. |
protected java.util.function.Supplier<?> |
findDefaultValueSupplier(java.lang.Object rawConfigValue,
java.lang.reflect.Field field,
java.lang.Object instance) |
protected <T,R> ValueDeserializer<T,R> |
findValueDeserializer(T value,
TypeConstraint resultType) |
static ObjectDeserializer |
standard()
Creates a new
ObjectDeserializer with the standard deserializers. |
protected final java.util.List<ValueDeserializerProvider<?,?>> generalProviders
protected ValueDeserializerProvider<?,?> defaultProvider
protected final boolean applyTransientModifier
public static ObjectDeserializerBuilder builder()
ObjectDeserializerBuilder with some standard deserializers already registered.public static ObjectDeserializerBuilder blankBuilder()
ObjectDeserializerBuilder without the standard deserializers already registered.public static ObjectDeserializer standard()
ObjectDeserializer with the standard deserializers.
This is equivalent to ObjectDeserializer.builder().build().
public <C extends java.util.Collection<V>,V> C deserializeToCollection(java.lang.Object configValue,
java.lang.Class<C> collectionClass,
java.lang.Class<V> valueClass)
C<V>.C - type of the collectionV - type of the values in the collectionconfigValue - config value to deserializecollectionClass - class of the collectionvalueClass - class of the values in the collectionpublic <M extends java.util.Map<java.lang.String,V>,V> M deserializeToMap(java.lang.Object configValue,
java.lang.Class<M> mapClass,
java.lang.Class<V> valueClass)
M<String, V>.M - type of the mapV - type of the values in the mapconfigValue - config value to deserializemapClass - class of the mapvalueClass - class of the values in the collectionpublic void deserializeFields(UnmodifiableConfig source, java.lang.Object destination)
Config as an object by transforming the config entries into fields.
The fields of the destination are modified through reflection.source - config to deserializedestination - object to store the result inpublic <R> R deserializeFields(UnmodifiableConfig source, java.util.function.Supplier<? extends R> destinationSupplier)
Config as an object of type R by transforming the config entries
into fields. A new instance of the object is created, and its fields are modified through reflection.R - type of the resulting objectsource - config to deserializedestinationSupplier - supplier of the resulting objectprotected <T,R> ValueDeserializer<T,R> findValueDeserializer(T value, TypeConstraint resultType)
protected java.util.function.Supplier<?> findDefaultValueSupplier(java.lang.Object rawConfigValue,
java.lang.reflect.Field field,
java.lang.Object instance)