Event Upcatsers

Hello Guys,

i have question regarding upcatsers, so if i have event that takes an object and i added more fields to that object do i need to implement upcaster or no need since the event parameters did not change. so for example CreatedEvent(int x , employee Employee)

class Employee {
String name,
int age

then we decided to add new field to Employee

class Employee {
String name,
int age,
int salary

do i still need to have upcaster or no need for that

Thanks in advance

Hi Skady!

Looking at your provided code samples, you technically don’t need an upcaster. When an old version of the event is deserialized, the salary property will be the default value for the int property, since it’s not present.
Note: This does depend on your deserialization options and how strict they are, which I cannot guess from the code provided here. I’m just assuming the most common scenario. By default we recommend deserialization to be as lenient as possible to prevent the need for upcasters.

However, in your business domain it may be invalid for someone to earn a 0 amount of money. In this case, you would need a check in your event handlers, or provide your own default value in an upcaster. Personally, I would go with the default value check in your handlers, but of course this is up to you!

I hope this helps, good luck,


Hi Mitchell,

Thank you so much for your detailed answer

1 Like