Hi StackOverflow!
I am just in the middle of the development of a new software component involving the Spring Framework. I like it but now i have a question regarding IoC and serialization.
Given i have this class (Omitted imports and package declaration):
public class EMailNotificationEndpoint implements NotificationEndpoint {
private List<String> notficationEmailAdresses = new ArrayList<String>();
transient private MailSender mailSender;
public EMailNotificationEndpoint(MailSender mailSender) {
this.mailSender = mailSender;
}
@Override
public void notify(Notification notification) {
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(notficationEmailAdresses.toArray(new String[notficationEmailAdresses.size()]));
simpleMailMessage.setSubject(notification.getType().toString());
simpleMailMessage.setText(notification.getMessage());
mailSender.send(simpleMailMessage);
}
}
NotificationEndpoint extends Serializable to ensure all implementations are serializable. The point is that i cannot serialize the MailSender (Which is org.springframework.mail.MailSender BTW) and want it to be injected at deserialisation time. Now my question is quire obvious: Can i do that? And if the answer is yes: how?
I'm free to change the interface and the implementations, so there should be a way to such a thing, even if this means i have to refactor the relevant classes.
Any Idea or hint is highly appreciated!