Skip to content

Migrating from 1.x to 2.x

ljacqu edited this page Oct 16, 2024 · 3 revisions
ConfigMe 2.0 is still in development, so this document is just an ongoing draft!

Property type changes

  • PrimitivePropertyType has been split to BooleanType, NumberType and StringType
  • Note: Strings are now converted to booleans/numbers if the representation matches, e.g. if String("4") is read from a property resource for an int property, its value will be determined to be the integer 4. ConfigMe 1.x discarded String values for all boolean and number types.
  • Note: if a conversion fails for an element inside an array, list or similar, ConfigMe will consider the resource not to be "fully valid" in more cases than before. This means that the configuration file will be resaved in more scenarios than previously if you are using a migration service. This change makes the behavior more consistent and should not affect you; however, please don't hesitate to open an issue if you need clarifications.

Other changes

  • Utils is renamed to FileUtils. Feel free to use the method(s) in FileUtils—it is part of the public API.
  • Constructor arguments in Property classes always start with the String path, then a type (if applicable), and the default value at the end. Some constructors have been changed to follow this order (e.g. TypeBasedProperty).

Bean mapper

General changes in Mapper (underlying converter of BeanProperty):

  • Getters and setters on bean classes are no longer relevant. The class's fields are taken as properties.
    • Consequently, @ExportName can only be set on fields.
    • To make ConfigMe ignore a field, add the transient modifier or add the new annotation @IgnoreInMapping
    • The @Transient annotation is no longer supported. Use ConfigMe's @IgnoreInMapping.
  • Note that, as with regular properties, more conversions are now possible, e.g. a string "3" will be converted to the integer 3 for an int field.
  • Java records can be used a bean property types. (This is not recommended.)

Leaf value handlers

If you don't override any Mapper behavior, you can skip this section.

  • LeafValueHandler has been split into LeafValueHandler and MapperLeafType. To support custom types in the bean mapper, you've had to implement your own LeafValueHandler. This is now being handled by a MapperLeafType. LeafValueHandler combines multiple MapperLeafType implementations. Previously, LeafValueHandler was doing both things via the same interface.
  • All default LeafValueHandler implementations that handled a specific type have changed and are mostly merged with the PropertyType implementations.
    • For example: BooleanLeafValueHandler (old) -> BooleanType (new); NumberLeafValueHandler (old) -> NumberType (new).

TODO old/new code samples

Misc

If you don't override any Mapper behavior, you can skip this section.

  • Moved MappingContext to package configme.beanmapper.context
  • TypeInformation is no longer provided by ConfigMe, but it now uses TypeInfo from the library ch.jalu.typeresolver

Property builders

The property builder implementations have been split and the methods for setting the default value have been changed as to be consistent:

  • A method defaultValue will always set the entire default value (e.g. whole default list of a list property) and may only be used once. Use addToDefaultValue to successively add default entries to a list/set/map/array property.
  • The property builder classes have changed. This should not greatly affect you if you are using the builder methods from PropertyInitializer. PropertyBuilder has been split into classes in the ch.jalu.configme.properties.builder package.
    • Old PropertyBuilder.ListPropertyBuilder is now CollectionPropertyBuilder#listBuilder
    • Old PropertyBuilder.SetPropertyBuilder is now CollectionPropertyBuilder#setBuilder
    • Old PropertyBuilder.ArrayPropertyBuilder is now ArrayPropertyBuilder#arrayBuilder
    • Old PropertyBuilder.InlineArrayPropertyBuilder is now ArrayPropertyBuilder#inlineArrayBuilder
    • Old PropertyBuilder.MapPropertyBuilder is now MapPropertyBuilder
    • Old PropertyBuilder.TypeBasedPropertyBuilder has been removed (along with PropertyInitializer#typeBasedProperty). Do you need this? Please open a new GitHub issue if so.

TODO add old/new examples

Inline array property type

  • InlineArrayConverter and StandardInlineArrayConverters have been merged and renamed to InlineArrayPropertyType. The class no longer is a separate type, but rather it implements PropertyType.
  • TODO specify string behavior (#382)

TODO add old/new examples