ExpediaGroup/bull

Automatic transformation between different Enum types

polarene opened this issue · 1 comments

Description
BULL already transforms enum values of the same type, that is the source and destination fields are of the same type. But when you need to map two different enum types you're forced to write a custom property transformer.
The desired feature is being able to map enum values of different types. Given the following types:

enum A {
    x, y
}

enum B {
    x, y
}

class Source {
    A type;
    // constructor, getters&setters...
}

class Destination {
    B type;
    // constructor, getters&setters...
}

we want the type field to be automatically mapped by the following instruction:

Destination d = new BeanUtils().getTransformer().transform(new Source(A.x), Destination.class);
assert d.getType() == B.x

The default behavior for this feature should be:

  • all enum values should map to constants with the same name
  • if the source enum has more values than destination, it should map to null

Feature no longer needed as it will be implemented as part of a new major release