Package org.pkl.config.java.mapper
Interface ValueMapper
public interface ValueMapper
Automatically converts Pkl objects to Java objects. Use
ValueMapperBuilder to create an
instance of this type, configured according to your needs.-
Method Summary
Modifier and TypeMethodDescriptiondefault <S,T> Converter <S, T> getConverter(org.pkl.core.PClassInfo<S> sourceType, 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, Type targetType) Returns the converter with the given source and target types.default <S,T> T Same asmap(Object, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference.<S,T> T Converts the given Pkl object to the given Java target type.static ValueMapperShorthand forValueMapperBuilder.preconfigured().build().Returns a value mapper builder that, unless further configured, will build value mappers with the same configuration as this value mapper.
-
Method Details
-
preconfigured
Shorthand forValueMapperBuilder.preconfigured().build(). -
map
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
Same asmap(Object, Type), except that the target type is narrowed fromTypetoClassto allow for better type inference. -
getConverter
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, 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.
-