Is it bad idea to have a condition in upcaster based on previous value

So I have this enum class

enum class ServerType {
   Cloud,
   Colocation,
   Dedicated
}

However our team decided to change the name of some value to

enum class ServerType {
   Cloud,
   DataCenter,
   Dedicated
}

So I’m considering making a conditional upcaster using SingleEventUpcaster. So I have custom implementation for upcaster and it may look like this.

AxonEventUpcaster.withType<ServerCreatedEvent>()
     .withVersion("1.0", "2.0")
     .upcaster { documentEditor -> 
        if (documentEditor["serverType"] == "Colocation") {
           return documentEditor.changeValue("serverType", "DataCenter")
        }
        return documentEditor
     }
    .build()

so is it good idea to put some condition in the upcaster. I’m worried because upcaster would add an overhead to event processor so it should be cheap and not complex operation.

Hi Werepon,

What serializer are you using? If you use Jackson, you should be able to add an alias for the old value, so you don’t even need an upcaster. As you already need the JacksonNode representation for the check, it doesn’t matter much performance-wise. This example might also be useful if you do need an upcaster.