Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: make Email serializable #218

Closed
ashokgelal opened this issue Aug 3, 2019 · 10 comments
Closed

Enhancement: make Email serializable #218

ashokgelal opened this issue Aug 3, 2019 · 10 comments

Comments

@ashokgelal
Copy link

Hi,
I need to serialize Email objects to be able to sent them later (processed by a different server using ActiveMQ). But since none of the classes implement java.io.Serializable interface, I'm not able to use auto serialization (unless I manually serialize/deserialize them, which, of course, is a lot of work).

I'm wondering if you have thought about having some of the classes (like Email, Recipient etc) implement the marker Serializable interface or not. If you have, is there any downside of implementing the interface that I'm missing? If you haven't thought of it, would you be open to having those classes implement the interface?

Thank you!

@bbottema
Copy link
Owner

bbottema commented Aug 6, 2019

Hi @ashokgelal, I would be open to that, depending on the impact on the code. But frankly speaking, I assumed Java serialization is a thing of the past and I'm not convinced yet it is still widely used. Therefor I'm a little reluctant to include this in the library.

@ashokgelal
Copy link
Author

ashokgelal commented Aug 6, 2019

I've done some research, but since it is just a marker interface and comes with no method of its own, there seems to be no side-effects of any kind. It really doesn't force users to do anything different but only makes it available if they want to use it.

... I assumed Java serialization is a thing of the past and I'm not convinced yet it is still widely used. Therefor I'm a little reluctant to include this in the library.

I understand your reluctance, and not that I'm a proponent of Java serialization either, but since serialization is at the core of Java, there are systems there that depend on this serialization mechanism (like ActiveMQ I'm using). Also, this library already uses classes from javax.mail package that implement Serializable (such as RecipientType class) and the "serialization flow" kind of abruptly stopping at this library defeats the purpose of having these core classes as serializables.

Anyway, I think the cost of making some of the classes of this library serializables is very low and would make it even more compatible with Java ecosystem making it open for even wider adoption. I hope you'll consider it seriously.

@bbottema
Copy link
Owner

bbottema commented Aug 9, 2019

there are systems there that depend on this serialization mechanism (like ActiveMQ I'm using)

Except that ActiveMQ doesn't depend on it, but merely supports it. Serializing email objects for transport is not interoperable, human readable and is not language agnostic, hence it not being used much anymore in general except for legacy systems. Normally you would put the JSON/XML/GSON whatever on the queue and create the email based on that in whatever language is receiving the data.

That being said, if it is just about adding a marker interface, I might not have much issue with that, but I seem to remember from school something about needing custom serialization (perhaps for nested objects that don't implement the interface).

It's been awhile, I have not dealt with serialise at any corporate company I worked for in the last 14 years.

@ashokgelal
Copy link
Author

Oops! I meant "supports by default" without having to do anything else.

Normally you would put the JSON/XML/GSON whatever on the queue and create the email based on that in whatever language is receiving the data.

That's exactly how I'm doing it right now. The reason I asked for this feature was because I was surprised to not being able to serialize an Email object as I was rapid prototyping something.

@bbottema
Copy link
Owner

bbottema commented Aug 11, 2019

Ok, you convinced me, as long as we don't have to implement manual serialization logic. If you feel up to it, I'll accept a PR on master. Else I will pick it up in some time.

@bbottema bbottema modified the milestones: 5.2.1, 5.3.0 Aug 11, 2019
@bbottema
Copy link
Owner

I can't guarantee serializibility, as I don't have control of the datasources used as attachments and embedded images... so that's a problem, unless I manually serialize/deserialize that, rather an involved job...

@bbottema bbottema changed the title Implementing Serializable interface Enhancement: make Email serializable Sep 27, 2019
bbottema pushed a commit that referenced this issue Sep 27, 2019
@bbottema bbottema added this to the 5.4.0 milestone Sep 27, 2019
@bbottema
Copy link
Owner

Will release 5.4.0 soon with this feature (make sure you use compatible serializable datasources). OSS Sonatype is having networking issues now though, so I can release to Maven Central for the moment.

@ashokgelal
Copy link
Author

Thanks!

@bbottema
Copy link
Owner

Released in 5.4.0. Note some fields have been made transient: data sources (attachments, embedded images), mime messages (forwarded email)

@metametadata
Copy link

We create AttachmentResources using jakarta.mail.util.ByteArrayDataSource and apparently such data sources are lost on serialization. Error on trying to send the deserialized email with attachments:

java.lang.NullPointerException: Cannot invoke "jakarta.activation.DataSource.getName()" because the return value of "org.simplejavamail.api.email.AttachmentResource.getDataSource()" is null

What could be a solution to this issue? Are there any ready-to-use serializable data source classes available somewhere?

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants