Package org.pkl.config.java.mapper
Interface ValueMapper
-
public interface ValueMapperAutomatically converts Pkl objects to Java objects. UseValueMapperBuilderto create an instance of this type, configured according to your needs.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <S,T>
Converter<S,T>getConverter(org.pkl.core.PClassInfo<S> sourceType, java.lang.Class<T> targetType)Same asgetConverter(PClassInfo, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference.<S,T>
Converter<S,T>getConverter(org.pkl.core.PClassInfo<S> sourceType, java.lang.reflect.Type targetType)Returns the converter with the given source and target types.default <S,T>
Tmap(S model, java.lang.Class<T> targetType)Same asmap(Object, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference.<S,T>
Tmap(S model, java.lang.reflect.Type targetType)Converts the given Pkl object to the given Java target type.static ValueMapperpreconfigured()Shorthand forValueMapperBuilder.preconfigured().build().ValueMapperBuildertoBuilder()Returns a value mapper builder that, unless further configured, will build value mappers with the same configuration as this value mapper.
-
-
-
Method Detail
-
preconfigured
static ValueMapper preconfigured()
Shorthand forValueMapperBuilder.preconfigured().build().
-
map
<S,T> T map(S model, java.lang.reflect.Type targetType)Converts the given Pkl object to the given Java target type. The Pkl object can be an entirePModuleor any value contained therein. SeePClassInfo.forValue(T)for which Java types are used to represent Pkl objects.When mapping to a generic target type, a fully parameterized type needs to be passed, e.g.
List<String>. Parameterized type literals can be created usingTypes, e.g.Types.listOf(String.class).If an error occurs during conversion, or if
ValueMapperdoes not know how to convert from the given object to the given target type, aConversionExceptionis thrown.
-
map
default <S,T> T map(S model, java.lang.Class<T> targetType)Same asmap(Object, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference.
-
getConverter
<S,T> Converter<S,T> getConverter(org.pkl.core.PClassInfo<S> sourceType, java.lang.reflect.Type targetType)
Returns the converter with the given source and target types. ThrowsConversionExceptionif no such converter exists.
-
getConverter
default <S,T> Converter<S,T> getConverter(org.pkl.core.PClassInfo<S> sourceType, java.lang.Class<T> targetType)
Same asgetConverter(PClassInfo, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference.
-
toBuilder
ValueMapperBuilder toBuilder()
Returns a value mapper builder that, unless further configured, will build value mappers with the same configuration as this value mapper. In other words, this is the inverse operation ofValueMapperBuilder.build(), except that a new builder is returned.
-
-