Class ValueMapperBuilder

java.lang.Object
org.pkl.config.java.mapper.ValueMapperBuilder

public final class ValueMapperBuilder extends Object
Builds a ValueMapper configured with appropriate conversions, converter factories, and type mappings.
  • Method Details

    • unconfigured

      public static ValueMapperBuilder unconfigured()
      Creates a builder without any preconfigured conversions, converter factories, or type mappings.
      Returns:
      a builder without any preconfigured conversions, converter factories, or type mappings
    • preconfigured

      public static ValueMapperBuilder preconfigured()
      Creates a builder preconfigured with all conversions, converter factories, and type mappings defined in this module.
      Returns:
      a builder preconfigured with all conversions, converter factories, and type mappings defined in this module
    • addConversion

      public ValueMapperBuilder addConversion(Conversion<?,?> conversion)
      Adds the given conversion. For conversions to a primitive type, a conversion to the corresponding wrapper type is automatically added.
      Parameters:
      conversion - the conversion to be added
      Returns:
      this
    • addConversions

      public ValueMapperBuilder addConversions(Collection<Conversion<?,?>> conversions)
      Adds the given conversions. For conversions to a primitive type, a conversion to the corresponding wrapper type is automatically added.
      Parameters:
      conversions - the conversions to be added
      Returns:
      this
    • setConversions

      public ValueMapperBuilder setConversions(Collection<Conversion<?,?>> conversions)
      Removes any existing conversions, then adds the given conversions.
    • getConversions

      public List<Conversion<?,?>> getConversions()
      Returns the currently set conversions.
    • addConverterFactory

      public ValueMapperBuilder addConverterFactory(ConverterFactory factory)
      Adds the given converter factory. Factories will be queried for converters in the same order as they are being added to this builder.
      Parameters:
      factory - the converter factory to be added
      Returns:
      this
    • addConverterFactories

      public ValueMapperBuilder addConverterFactories(Collection<ConverterFactory> factories)
      Adds the given converter factories. Factories will be queried for converters in the same order as they are being added to this builder.
      Parameters:
      factories - the converter factories to be added
      Returns:
      this
    • setConverterFactories

      public ValueMapperBuilder setConverterFactories(Collection<ConverterFactory> factories)
      Removes any existing converter factories, then adds the given factories.
    • getConverterFactories

      public List<ConverterFactory> getConverterFactories()
      Returns the currently set converter factories.
    • addTypeMapping

      public ValueMapperBuilder addTypeMapping(TypeMapping<?,?> mapping)
      Adds the given type mapping.
      Parameters:
      mapping - the type mapping to be added
      Returns:
      this
    • addTypeMappings

      public ValueMapperBuilder addTypeMappings(Collection<TypeMapping<?,?>> mappings)
      Adds the given type mappings.
      Parameters:
      mappings - the type mappings to be added
      Returns:
      this
    • setTypeMappings

      public ValueMapperBuilder setTypeMappings(Collection<TypeMapping<?,?>> mappings)
      Removes any existing type mappings, then adds the given mappings.
    • getTypeMappings

      public List<TypeMapping<?,?>> getTypeMappings()
      Returns the currently set type mappings.
    • build

      public ValueMapper build()
      Builds a mapper with the configured conversions, converter factories, and type mappings. If desired, the same builder can be used to build multiple mappers.
      Returns:
      a mapper with the configured conversions, converter factories, and type mappings