I am using akka 2.4 with eventstore 4.0.0.7 and I am new to event adapters
I have a Old event known us UserEvent (Class) which has only one class member known as email. Now I am switching to username and therefore this event variable email changes to username.
I have written a adapter to catch all UserEvent instances using instanceof and then convert it into UserEventV2 and return the new Object
Currently My adapter nor the akka system throws any error on console - But I get username as null, when the domain object is recovered.
Here’s my code
class UserEventEmailToUsername implements EventAdapter {
@Override
public String manifest(Object event) {
return ""; // if no manifest needed, return ""
}
@Override
public Object toJournal(Object event) {
return event; // identity
}
@Override
public EventSeq fromJournal(Object event, String manifest) {
if (event instanceof UserEvent) {
UserEvent evt = (UserEvent) event;
return EventSeq.single(new UserEventWithUsernameVersion(evt.getEmail()));
}
return EventSeq.single(event); // identity
}
}
here’s my old event and new event class
@AllArgsConstructor
@ToString
public class UserEvent extends EventWithTimeStamps implements Serializable {
private static final long serialVersionUID = 1L;
@Getter private String email;
}
@AllArgsConstructor
@ToString
public class UserEventWithUsernameVersion extends EventWithTimeStamps implements Serializable {
private static final long serialVersionUID = 1L;
@Getter private String username;
}
akka configuration
akka.persistence.journal {
inmem {
event-adapters {
userEvent-upcasting = "com.wt.domain.write.events.adapter.UserEventEmailToUsername"
}
event-adapter-bindings {
"com.wt.domain.write.events.UserEvent" = [userEvent-upcasting]
}
}
}
am I doing something wrong ? if not then why am I getting null value in username ?