Why core objects like JsonArray, Buffer, JsonObject are not Serializable?

481 views
Skip to first unread message

Oren Shvalb

unread,
May 15, 2016, 6:02:10 PM5/15/16
to vert.x
Hello,

The mentioned classes are wrappers on a java.util containers which are Serializable. 
so, why not to expose this interface for the wrappers as well?

For example:

io.vertx.core.json.JsonObject    wraps     java.util.ArrayList   which implements Serializable.

same goes to Buffer and JsonObject.


The thing is that, if I would like to store JsonArray in Hazelcast map I can't because it's not implementing Serializable!

Is this something that can be fixed for the future?

If not, is there a workaround I can do to still be able to store it in HZ ?

Thank you!

Tim Fox

unread,
May 16, 2016, 1:46:16 AM5/16/16
to ve...@googlegroups.com
If you convert them to strings you can serialize them in Hazelcast
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/7f366025-49a0-4a48-a255-2c3f69cd6c9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oren Shvalb

unread,
May 16, 2016, 7:15:40 AM5/16/16
to ve...@googlegroups.com
Yes, but then when I take it out from HZ map I wouldn't be able to convert them back to the class.

Why these classes don't implement Serialzable? Is there a reason for that?

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/zENKozSHvGo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.

Tim Fox

unread,
May 16, 2016, 7:39:35 AM5/16/16
to ve...@googlegroups.com
On 16/05/16 12:15, Oren Shvalb wrote:
Yes, but then when I take it out from HZ map I wouldn't be able to convert them back to the class.

Sure you can:

JsonObject obj = new JsonObject(stringIGotFromHazelcast);

Internally in Vert.x (e.g. if you add a JsonObject to a clustered map) we serialize Json objects as strings.

(See the ClusterSerializable interface)



Why these classes don't implement Serialzable? Is there a reason for that?

Java serialization is very inefficient. It's much more efficient to let Jackson serialize to a string, and then use that as the serialized form.

Oren Shvalb

unread,
May 16, 2016, 7:49:57 AM5/16/16
to ve...@googlegroups.com
By saying "i wouldn't be able to convert..." 
My case is a bit more complicated than storing JsonObject directly to map. I store custom classes which JsonObject is just another field in the class. Hence my problem.

Sent from my iPhone

Jochen Bedersdorfer

unread,
May 16, 2016, 7:22:47 PM5/16/16
to vert.x
You could have your custom class implement https://docs.oracle.com/javase/7/docs/api/java/io/Externalizable.html and then do the string conversion in readExternal/writeExternal.

Oren Shvalb

unread,
May 16, 2016, 8:37:33 PM5/16/16
to ve...@googlegroups.com
Thank you for this idea! - I will look into it.

:-)

Tim Fox

unread,
May 17, 2016, 2:56:20 AM5/17/16
to ve...@googlegroups.com
If you want to store in a HZ map _directly_ then DataSerializable should be implemented:

http://docs.hazelcast.org/docs/3.5/manual/html/dataserialization.html

Oren Shvalb

unread,
May 17, 2016, 8:24:52 AM5/17/16
to ve...@googlegroups.com
Thank you for this comment - I will look into this interface - it looks like the right solution!

Reply all
Reply to author
Forward
0 new messages